Created
August 17, 2018 21:33
-
-
Save kwalrath/b62c036c308fd018ff37da5d77670140 to your computer and use it in GitHub Desktop.
playing with async-await
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
| import 'dart:async'; | |
| Future<void> f() async { | |
| print('1: before await'); | |
| await null; | |
| print('2: after await'); | |
| } | |
| // 3: before f() | |
| // 1: before await | |
| // 4: after f() | |
| // 2: after await | |
| // Future<void> main() async { | |
| Future<void> withoutAwait() async { | |
| print('3: before f()'); | |
| f(); | |
| print('4: after f()'); | |
| } | |
| // 5: before await f() | |
| // 1: before await | |
| // 2: after await | |
| // 6: after await f() | |
| // Future<void> main() async { | |
| Future<void> withAwait() async { | |
| print('5: before await f()'); | |
| await f(); | |
| print('6: after await f()'); | |
| } | |
| // 7: before calling withoutAwait | |
| // | |
| // 3: before f() | |
| // 1: before await | |
| // 4: after f() | |
| // | |
| // 8: after calling withoutAwait | |
| // | |
| // 5: before await f() | |
| // 1: before await | |
| // | |
| // 9: after calling withAwait | |
| // | |
| // 2: after await | |
| // 2: after await | |
| // 6: after await f() | |
| main() async { // NO AWAITS | |
| print('7: before calling withoutAwait\n'); | |
| withoutAwait(); | |
| print('\n8: after calling withoutAwait\n'); | |
| withAwait(); | |
| print('\n9: after calling withAwait\n'); | |
| } | |
| // 7: before calling withoutAwait | |
| // | |
| // 3: before f() | |
| // 1: before await | |
| // 4: after f() | |
| // 2: after await | |
| // | |
| // 8: after calling withoutAwait | |
| // | |
| // 5: before await f() | |
| // 1: before await | |
| // 2: after await | |
| // 6: after await f() | |
| // | |
| // 9: after calling withAwait | |
| // main() async { // WITH AWAITS | |
| // print('7: before calling withoutAwait\n'); | |
| // await withoutAwait(); | |
| // print('\n8: after calling withoutAwait\n'); | |
| // await withAwait(); | |
| // print('\n9: after calling withAwait\n'); | |
| // } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment