Created
September 5, 2020 01:51
-
-
Save Grohden/8430ebb2f2cc046a9cf2f274aea06ae4 to your computer and use it in GitHub Desktop.
Sequential await vs non sequential
This file contains hidden or 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 list = [1,6,3,2,4,5]; | |
print('Sequential'); | |
for(final time in list) { | |
await Future.delayed(Duration(seconds: time)); | |
print(time); | |
} | |
print('Not sequential'); | |
list.forEach((time) async { | |
await Future.delayed(Duration(seconds: time)); | |
print(time); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment