问题
It is possible write similar code in Dart language?
int i;
try {
i = await getResultAsync();
} catch(exception) {
// Do something
}
回答1:
Basic support is already available.
See https://www.dartlang.org/articles/await-async/ for more details.
main() async {
print(await foo());
try {
print(await fooThrows());
} catch(e) {
print(e);
}
}
foo() async => 42;
fooThrows() async => throw 'Anything';
回答2:
Not for now. See issue Support for "await" in Dart.
来源:https://stackoverflow.com/questions/17490888/dart-language-support-async-await-programming-style-or-similar