Created
February 27, 2023 18:54
-
-
Save knaeckeKami/99f7f2746285d170b39437a1d2d4182e to your computer and use it in GitHub Desktop.
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
void main() { | |
asyncInit(); | |
} | |
Future<void> asyncInit() async { | |
await Future.wait([ | |
for (var i = 0; i < 10; i++) ...[ | |
asyncParent(), | |
], | |
]); | |
print('---------------------'); | |
await Future.wait([ | |
for (var i = 0; i < 10; i++) ...[ | |
syncParent(), | |
], | |
]); | |
print('---------------------'); | |
await asyncParent(); | |
} | |
Future<String> asyncParent() async { | |
final s = Stopwatch()..start(); | |
final result = await asyncChild(); | |
s.stop(); | |
print('asyncParent: ${s.elapsedMilliseconds}'); | |
return result; | |
} | |
Future<String> asyncChild() async { | |
final s = Stopwatch()..start(); | |
const result = 'foo'; | |
s.stop(); | |
print('asyncChild: ${s.elapsedMilliseconds}'); | |
return result; | |
} | |
Future<String> syncParent() async { | |
final s = Stopwatch()..start(); | |
final result = syncChild(); | |
s.stop(); | |
print('syncParent: ${s.elapsedMilliseconds}'); | |
return result; | |
} | |
String syncChild() { | |
final s = Stopwatch()..start(); | |
const result = 'foo'; | |
s.stop(); | |
print('syncChild: ${s.elapsedMilliseconds}'); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment