Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在js外层无法使用await #20

Open
MoonRune opened this issue Jul 7, 2021 · 1 comment
Open

在js外层无法使用await #20

MoonRune opened this issue Jul 7, 2021 · 1 comment

Comments

@MoonRune
Copy link

MoonRune commented Jul 7, 2021

相同的dart code。在js的 async function中使用await 是可以的
但是在js的外部 使用
var tmp=await http("https://www.baidu.com");
会报错
SyntaxError: expecting ';' at <eval>:228

@ekibun
Copy link
Owner

ekibun commented Jul 8, 2021

本身是同步的,会直接返回结果,如果要await可以包一层匿名函数:

(async () {
   var tmp = await http("https://www.baidu.com");
})();

这样在dart里面收到的是Future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants