Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Last active March 18, 2022 22:01
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 danielgomezrico/ee1155b584542e30f6aee9658cc84978 to your computer and use it in GitHub Desktop.
Save danielgomezrico/ee1155b584542e30f6aee9658cc84978 to your computer and use it in GitHub Desktop.
List.await • dart: example to see the order of the returned results
import 'dart:async';
Future main() async {
print('start');
final li = await Future.wait([fetch(4), fetch(6)]);
print('results: ${li[0]} ${li[1]}'); // results: 4 2
final li2 = await Future.wait([fetch(6), fetch(3)]);
print('results 2: ${li2[0]} ${li2[1]}'); // results: 6 3
}
Future<int> fetch(int duration) {
return Future.delayed(Duration(seconds: duration), () {
return duration;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment