Last active
March 18, 2022 22:01
-
-
Save danielgomezrico/ee1155b584542e30f6aee9658cc84978 to your computer and use it in GitHub Desktop.
List.await • dart: example to see the order of the returned results
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
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