Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. void main() async {
  2. final t1 = () => Future.delayed(Duration(seconds: 1), () => print('1'));
  3. final t2 = () => Future.delayed(Duration(seconds: 3), () => print('3'));
  4. final t3 = () => Future.delayed(Duration(seconds: 2), () => print('2'));
  5.  
  6. final timers = [t1, t2, t3];
  7.  
  8. print('Running');
  9.  
  10. Stopwatch stopwatch = new Stopwatch()..start();
  11. // for (final timer in timers) {
  12. // await timer();
  13. // }
  14. await Future.wait(timers.map((timer) => timer()));
  15. print('executed in ${stopwatch.elapsed}');
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement