问题:与常规函数的return语句相比,是否存在(并且,如果是,在何种程度上)引擎运行时的计算开销以声明函数async
和最终await
?
async function foo() {
var x = await bar(); // <--- bar() is non-blocking so await to get the return value
return x; // the return value is wrapped in a Promise because of async
}
Run Code Online (Sandbox Code Playgroud)
与
function foo() {
var x = bar(); // <--- bar() is blocking inside its body so we get the return value
return new Promise(resolve => { resolve(x); }); // return a Promise manually
}
Run Code Online (Sandbox Code Playgroud)
背景:
由于Javascript(和Nodejs)采用异步方向,为什么他们不 …