Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main() async {
- final t1 = () => Future.delayed(Duration(seconds: 1), () => print('1'));
- final t2 = () => Future.delayed(Duration(seconds: 3), () => print('3'));
- final t3 = () => Future.delayed(Duration(seconds: 2), () => print('2'));
- final timers = [t1, t2, t3];
- print('Running');
- Stopwatch stopwatch = new Stopwatch()..start();
- // for (final timer in timers) {
- // await timer();
- // }
- await Future.wait(timers.map((timer) => timer().timeout(Duration(seconds: 2), onTimeout: () => print('timeout'))));
- print('executed in ${stopwatch.elapsed}');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement