Skip to content

Instantly share code, notes, and snippets.

@yefim
Created September 6, 2019 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yefim/0d6d703b111b8d7f5cca6e6bb0630ab7 to your computer and use it in GitHub Desktop.
Save yefim/0d6d703b111b8d7f5cca6e6bb0630ab7 to your computer and use it in GitHub Desktop.
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