问题描述
- 设完成为Call(执行者,未定义,«resolvingFunctions。[[Resolve]],resolvingFunctions。[[Reject]]»)。
- 如果完成是突然完成,则
- 令status为Call(resolvevingFunctions。[[Reject]],undefined,«completion。[[value]]»)。
- ReturnIfAbrupt(状态)。
ES6标准指出,承诺的实现 是异步的(请参见25.4.5.3Promise.prototype.then
节和随附的25.4.5.3.1节PerformPromiseThen
)。我已将相关材料放在下面。
然后履行承诺
- 否则,如果promise的[[PromiseState]]内部广告位的值“已实现”,
- 令value为promise的[[PromiseResult]]内部广告位的值。
- 执行EnqueueJob(“ PromiseJobs”,PromiseReactionJob,«fulfillReaction,value»)。
- 否则,如果promise的[[PromiseState]]内部广告位的值被“拒绝”,
- 假设reason为promise的[[PromiseResult]]内部广告位的值。
- 执行EnqueueJob(“ PromiseJobs”,PromiseReactionJob,«rejectReaction,reason»)。
:传递给promise的函数是同步执行的,但是后续then
调用始终是异步执行的。
解决方法
假设我有这段代码
function y(resolve,reject)
{
console.log("Result");
resolve();
}
var promise = new Promise(y);
我想知道的是该函数是否y
将异步执行。