Skip to content

Instantly share code, notes, and snippets.

@knaeckeKami
Created February 27, 2023 18:54
Show Gist options
  • Save knaeckeKami/99f7f2746285d170b39437a1d2d4182e to your computer and use it in GitHub Desktop.
Save knaeckeKami/99f7f2746285d170b39437a1d2d4182e to your computer and use it in GitHub Desktop.
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