Last active
September 13, 2018 23:38
-
-
Save yeoupooh/9919f9d5c7cd44ac1ac79458e12c70a5 to your computer and use it in GitHub Desktop.
Async example in dart
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
import 'dart:async'; | |
Future doSomething() { | |
print('before future'); | |
var future = new Future(() { | |
print('before done'); | |
for (var i = 0; i < 1000; i++) { | |
// do something | |
} | |
print('done'); | |
}); | |
print('after future'); | |
return future; | |
} | |
Future<void> print1() async { | |
print('before 1'); | |
var future = await doSomething(); | |
print(1); | |
// future.then((v) { | |
// print('future then'); | |
// }); | |
return future; | |
} | |
Future<void> print2() async { | |
print('before 2'); | |
var future = await doSomething(); | |
print(2); | |
// future.then((v) { | |
// print('future then'); | |
// }); | |
return future; | |
} | |
void print3() { | |
print(3); | |
} | |
void main() { | |
print1(); | |
print2(); | |
print3(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment