Re: [Promises] Out-of-sequence method invocation behavior

On Sun, Jul 28, 2013 at 6:46 PM, Rich Tibbett <richt@opera.com> wrote:
> In the XMLHttpRequest spec the state machine is used to define the expected
> behavior when XHR object methods are called out of sequence. For example, if
> I invoke send() when an XHR object is not in the |opened| state then
> implementations are expected to throw an InvalidStateError exception [1].
>
> What is the expected behavior of Promises wrt out of sequence method
> invocation? Specifically, if I call myPromise.then(func) after the Promise
> has already reached the |fulfilled| state what should the UA do? Throw an
> InvalidStateError (ala XHR), invoke the relevant fulfill or error callback
> based on the object's previously established resolution or some other
> behavior?

This question suggests you may not fully understand the purpose of
Promises.  Nothing special happens, because this is an intended
interaction mode.  Promises can have callbacks registered against them
either before *or* after they've fulfilled; either way, they'll call
the callback with their value as normal.  There's no such thing as
late registration, because eliminating that precise pitfall is one of
the major reasons Promises are better than Events for some things.

The only relevant state machinery operations are the accept()/reject()
methods on the resolver, but they just silently fail if called when
the promise has already been fulfilled.

~TJ

Received on Monday, 29 July 2013 02:08:31 UTC