Created
January 31, 2020 05:24
-
-
Save bsutton/a42cce3edf01b222206a627e8c8106af to your computer and use it in GitHub Desktop.
completers and await
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'; | |
void main() { | |
print('hi'); | |
var res = doCalc(); | |
print('value = ${res}'); | |
res.then((result) => print('result = $result')); | |
} | |
Future<int> doCalc() async | |
{ | |
var done = Completer<int>(); | |
await Future.delayed(Duration(seconds: 4), | |
() { | |
done.complete(10); | |
}); | |
return done.future; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment