Promises Consensus

Domenic Denicola domenic at domenicdenicola.com
Mon Aug 19 10:47:21 PDT 2013


From: Mark S. Miller [erights at google.com]


> No. Assuming that p and q are both promises and that q is pending, p is resolved to q when either p adopts q or p accepts q. From the .then perspective these are the same, so we'd say p follows q or p is resolved to q. In neither care would p.then fire until q is settled (fulfilled or rejected). However, there's an operational difference between "p adopts q" and "p accepts q" at the .flatMap level: p adopts q does not fire p.flapMap. p accepts q does fire p.flatMap with q as the acceptance value.

After being confused on this point for a while, I hashed it out with Tab over IRC (thanks Tab!) and thought I'd share my moment of enlightenment with all involved.

```js
var foreverPending = new Promise(() => {});

var notAcceptedAndNotResolved = Promise.resolve(foreverPending);
var acceptedButNotResolved = Promise.fulfill(foreverPending);

// Neither of them are fulfilled, so the distinction doesn't matter for `then` usage.
notAcceptedAndNotResolved.then(() => console.log("this will never happen (never fulfilled)"));
acceptedButNotResolved.then(() => console.log("this will never happen (never fulfilled)"));

// But it matters for `flatMap` usage.
notAcceptedAndNotResolved.flatMap(() => console.log("this will never happen (never accepted)"));
acceptedButNotResolved.flatMap(() => console.log("this *will* happen"));
```




More information about the es-discuss mailing list