Skip to content

Instantly share code, notes, and snippets.

@samramez
Created April 30, 2020 03:06
Show Gist options
  • Save samramez/a209381bff8a8061be6dbff2338f9e2d to your computer and use it in GitHub Desktop.
Save samramez/a209381bff8a8061be6dbff2338f9e2d to your computer and use it in GitHub Desktop.
// Sample Dart code for making parallel async calls.
void main() {
Future.wait([firstAsync(), secondAsync(), thirdAsync()])
.then((List responses) => print("All tasks are done"))
.catchError((e) => print(e));
}
Future firstAsync() async {
print("firstAsync started");
await Future<String>.delayed(const Duration(seconds: 3));
print("firstAsync DONE");
}
Future secondAsync() async {
print("secondAsync started");
await Future<String>.delayed(const Duration(seconds: 3));
print("secondAsync DONE");
}
Future thirdAsync() async {
print("thirdAsync started");
await Future<String>.delayed(const Duration(seconds: 3));
print("thirdAsync DONE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment