Promise/Future: asynchrony in 'then'
claus.reinke at talk21.com
Tue Apr 30 09:43:58 PDT 2013
The promises-aplus spec has a note that confuses me
1. In practical terms, an implementation must use a mechanism such
as setTimeout, setImmediate, or process.nextTick to ensure that
onFulfilled and onRejected are not invoked in the same turn of the
event loop as the call to then to which they are passed.
I have not yet been able to decide whether DOMFuture has a
similar provision, or how this note is meant to be interpreted.
The aspect that worries me is that this note is attached not to the
creation of promises but to the definition of 'then'. Is that because
of the implicit return lifting (if 'then' callbacks do not return promises,
wrap the return in a new promise), or is there something else going on?
As long as the 'then' callbacks return Promises, the idea of resolved
Promise creation as left and right identity of 'then'
Promise.of(value).then(cb) = cb(value)
promise.then(Promise.of) = promise
would seem to require no additional delays introduced by 'then'
(promise creation decides semantics/delays, 'then' only passes on
Could someone please clear up this aspect? How is that note meant
to be interpreted, and do other Promise/Future specs have similar
PS. Prompted by this blog post:
More information about the es-discuss