当前位置:网站首页>Dart:在循环中使用 Async 和 Await
Dart:在循环中使用 Async 和 Await
2022-04-22 22:41:00 【大前端之旅】
Dart:在循环中使用 Async 和 Await

在 Dart(以及 Flutter)中,您可以使用Future.forEach在循环中顺序执行同步操作。下面的示例程序将打印从 1 到 10 的数字。每次打印完一个数字,它会等待 3 秒,然后再打印下一个数字。
//大前端之旅
void main() async {
final items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
await Future.forEach(items, (item) async {
print(item);
await Future.delayed(const Duration(seconds: 3));
});
}
另一种方法是在语法中使用for … ,如下所示:
// 大前端之旅
void main() async {
final items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (int item in items) {
print(item);
await Future.delayed(const Duration(seconds: 3));
}
}
版权声明
本文为[大前端之旅]所创,转载请带上原文链接,感谢
https://jianguo.blog.csdn.net/article/details/124334567
边栏推荐
- Sequel: a few simple but useful words
- 哪怕 30 年寒窗苦讀,也有可能離財富很遠……
- Anti DDoS attack forwarding IP. Is the advanced anti IP of chess and card games easy to use?
- 用 Flutter 写一个精美的登录页面(最新版)
- MySQL表的增删改查(进阶)
- 阿里云服务器如何隐藏真实ip
- Talking about constructor in detail
- 等价多米诺骨牌对的数量-c语言实现
- Advanced multithreading (8) -- thread pool
- ansible作业1
猜你喜欢

Difference between ov code signature and ev code signature certificate

Even if you study hard for 30 years, you may be far from wealth

Acl2022 | using Chinese language hierarchy heterogeneity map to strengthen the pre training language model
![[MRCTF2020]Ez_ bypass](/img/11/6278377c6273eca16716bc73c8a63b.png)
[MRCTF2020]Ez_ bypass

scanpy find resolution

Principle of leftmost matching principle

Robot OS系统架构设计

RPC详解

Basic use and principle of Minio

Minio基本使用与原理
随机推荐
最左匹配原则的原理
做到与做好,国产引擎 Cocos 如何丛林突围?
3. 源码
吴恩达-深度学习微课-第四课
What is the function of timestamp and how to apply for it?
行人重识别综述之Person Re-identification:Past, Present and Future
新闻速递 I MobTech通过中国信通院“安全专项评测”
Multi thread thread communication (wait notify, await single, park unpark)
GBase 8s V8. 8 SQL Guide: Tutorial - 6.2.2 (1)
c#获取调用者的类名或者方法名
Talking about constructor in detail
The form of JSP is submitted to servlet, but JS is invalid
API 网关实现功能
scanpy find resolution
挖财学堂的证券账户可靠吗?现在开户安全不?用哪个券商比较好?
OV代码签名和EV代码签名证书区别
MySQL表的增删改查(进阶)
聚类数据生成函数--make_blobs()
Cap theory
Study notes 2-0417