Created
September 6, 2019 20:41
-
-
Save yefim/0d6d703b111b8d7f5cca6e6bb0630ab7 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), () => true); // should short circuit | |
final t2 = () => Future.delayed(Duration(seconds: 3), () => true); | |
final t3 = () => Future.delayed(Duration(seconds: 2), () => false); | |
final timers = [t1, t2, t3]; | |
bool isDirty = false; | |
print('Running'); | |
Stopwatch stopwatch = new Stopwatch()..start(); | |
try { | |
await Future.wait(timers.map((timer) { | |
return timer().timeout(Duration(seconds: 2), onTimeout: () => false).then((isDirty) { | |
if (isDirty) { | |
throw new Error(); | |
} | |
}); | |
}), eagerError: true); | |
} catch (e) { | |
isDirty = true; | |
} | |
print('executed in ${stopwatch.elapsed}'); | |
print('isDirty = $isDirty'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment