Skip to content

Instantly share code, notes, and snippets.

@yeoupooh
Last active September 13, 2018 23:38
Show Gist options
  • Save yeoupooh/9919f9d5c7cd44ac1ac79458e12c70a5 to your computer and use it in GitHub Desktop.
Save yeoupooh/9919f9d5c7cd44ac1ac79458e12c70a5 to your computer and use it in GitHub Desktop.
Async example in dart
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