Async/await in List.forEach()

前端 未结 4 570
执笔经年
执笔经年 2020-12-15 15:10

I\'m writting some kind of bot (command line application) and I\'m having trouble with async execution when I\'m using \"forEach\" method. Here is a simplified code of what

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 15:52

    I don't think it's possible to achieve what you want with the forEach method. However it will work with a for loop. Example;

    asyncOne() async {
      print("asyncOne start");
      for (num number in [1, 2, 3])
        await asyncTwo(number);
      print("asyncOne end");
    }
    

提交回复
热议问题