【发布时间】:2021-11-29 18:35:57
【问题描述】:
想要推迟某些代码行,使用 await Future 并且效果很好,问题是它推迟了它之后的所有代码,我需要它推迟某些代码行,同时继续执行其余的代码立即编码
void main() async {
for (int i = 0; i < 5; i++) {
await Future.delayed(Duration(seconds: 1));
//postpone just next line or few lines of code
print('postpone this line of code ${i + 1}');
print('postpone me too');
}
//should execute without being postponed
print('continue imediately without being postponed by await Future');
}
这可以通过 await Future 或其他一些功能实现吗?
【问题讨论】:
标签: dart async-await future