小编Sim*_*mon的帖子

Javascript异步函数的开销是多少?

问题:与常规函数的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)采用异步方向,为什么他们不 …

javascript asynchronous node.js

10
推荐指数
1
解决办法
1693
查看次数

标签 统计

asynchronous ×1

javascript ×1

node.js ×1