Skip to content

Instantly share code, notes, and snippets.

@yefim
Created September 6, 2019 20:07
Show Gist options
  • Save yefim/c3c0359632b3b1848d0150837202627c to your computer and use it in GitHub Desktop.
Save yefim/c3c0359632b3b1848d0150837202627c to your computer and use it in GitHub Desktop.
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