SHARE
TWEET

Untitled

a guest Sep 17th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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().timeout(Duration(seconds: 2), onTimeout: () => print('timeout'))));
  15.   print('executed in ${stopwatch.elapsed}');
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top