Created
March 5, 2021 15:19
-
-
Save artem-zaitsev/82f36cbf0e6a3f94ddda0ba67b9fbab8 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() { | |
awaited(); | |
} | |
void syncFuture() { | |
print("hello first!"); | |
Future((){ | |
print("this is hello from future"); | |
}).then((_) { | |
print("Future completed"); | |
}); | |
print("bye!"); | |
for(var i=0;i<5;i++) { | |
print("busy work"); | |
} | |
} | |
//// async / await //// | |
void awaited() async { | |
printA(); | |
printB(); | |
await printC("main"); | |
await printD(); | |
} | |
void printA(){ | |
print("A"); | |
} | |
void printB() async { | |
print("B started"); | |
await printC("B"); | |
print("end B"); | |
} | |
void printC(String from) async { | |
print("C started from $from"); | |
await Future((){ | |
print("C running in future $from"); | |
}).then((_){ | |
print("Future completed"); | |
}); | |
print("end of C from $from"); | |
} | |
void printD() async { | |
print("D"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment