Dart语言支持异步/等待编程风格,还是类似? [英] Dart language support async/await programming style, or similar?

查看:135
本文介绍了Dart语言支持异步/等待编程风格,还是类似?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在Dart语言中编写类似的代码?

It is possible write similar code in Dart language?

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


推荐答案

基本支持已可用。

请参见 https://www.dartlang.org/articles/await-async/ 了解详情。

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';

这篇关于Dart语言支持异步/等待编程风格,还是类似?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆