我看了一下说明书,发现了以下信息。简而言之
async function
去糖机
Promise
所以,
是的,异步函数返回承诺
.
根据
tc39 spec
,以下是正确的:
async function <name>?<argumentlist><body>
去糖:
function <name>?<argumentlist>{ return spawn(function*() <body>, this); }
在哪里?
spawn
“是对以下算法的调用”:
function spawn(genF, self) {
return new Promise(function(resolve, reject) {
var gen = genF.call(self);
function step(nextF) {
var next;
try {
next = nextF();
} catch(e) {
// finished with failure, reject the promise
reject(e);
return;
}
if(next.done) {
// finished with success, resolve the promise
resolve(next.value);
return;
}
// not finished, chain off the yielded promise and `step` again
Promise.resolve(next.value).then(function(v) {
step(function() { return gen.next(v); });
}, function(e) {
step(function() { return gen.throw(e); });
});
}
step(function() { return gen.next(undefined); });
});
}