Dart语言支持异步/等待编程风格,还是类似?

时间:2013-07-05 14:09:18

标签: dart dart-async

可以用Dart语言编写类似的代码吗?

int i;
try {
  i = await getResultAsync();
} catch(exception) {
  // Do something
}

2 个答案:

答案 0 :(得分:3)

基本支持已经可用 有关详细信息,请参阅https://www.dartlang.org/articles/await-async/

main() async {
  print(await foo());
  try {
    print(await fooThrows());
  } catch(e) {
    print(e);
  }
}

foo() async => 42;

fooThrows() async => throw 'Anything';

答案 1 :(得分:2)

不是现在。请参阅问题Support for "await" in Dart