承诺如何得到解决和待决?

时间:2017-04-24 16:23:01

标签: javascript promise

spec says

  

已解决的承诺可能正在等待,履行或拒绝。

如何解决和待决承诺?

1 个答案:

答案 0 :(得分:3)

它链接到的部分就在那里:

  

承诺已解决如果已解决或已被“锁定”以匹配另一个承诺的状态。 [...]

其他承诺可能仍未决定。让我们来看一个例子:

var p = new Promise(resolve => setTimeout(resolve, 1000));
var q = Promise.resolve(p);

// At this point `q` is resolved / "locked in"  but still pending
// because the `p` promise is also still pending.

// Only after the timeout has passed, the `p` promise will resolve/settle 
// and `q` will assume the inner promises state.

看起来Bergi围绕承诺术语写了一个非常全面的答案:What is the correct terminology for javascript promises