Created
September 6, 2019 20:07
-
-
Save yefim/c3c0359632b3b1848d0150837202627c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment