Dart language support async/await programming style, or similar? [duplicate]

a 夏天 提交于 2019-12-19 17:01:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!