I'm trying to understand proper execution order of async functions in Dart. Here is a code that puzzles me:
void main() async {
print(1);
f1();
print(3);
}
void f1() async {
print(2);
}
According to spec first main() will be executed then f1(). So I expect output:
1
3
2
However real output is:
1
2
3
Does it mean f1() is executed synchronously?
However if I add await Future.delayed(Duration.zero); to f1() before print the output is as I expect:
void main() async {
print(1);
f1();
print(3);
}
void f1() async {
await Future.delayed(Duration.zero);
print(2);
}
1
3
2
Can anyone explain that?