Re: [DOM Futures] Is there a typo in future wrapper callback?

Sean Hogan <[email protected]>
Newsgroups gmane.comp.web.dom.general
Message-ID <[email protected]>
On 15/05/13 11:37 PM, Sean Hogan wrote:
> (Posting this again because my copy-and-paste inserted hyperlinks the 
> first time)
>
> I'm perplexed by the second step of future wrapper callbacks:
>
> Set callback's `callback this value` to resolver's associated future.
>
> Assuming this results in the equivalent of:
>
>     callback.call(future, value)
>
> then I can't work out the purpose.
> Is there a use for calling `future.then()`, etc inside the callback?
>
> There is also a potential failure mode in the unlikely case that the 
> callback returns `this`, that is, returns the current future object. 
> The result would be the following:
>
>     future.then(function() { return this; }); // returns future
>
>     run the associated resolver's resolve() with future
>
>     future has a `then` method so it is called with callbacks that 
> would run future's resolve and reject algorithms
>
>     now future is still pending until those callbacks get called, but 
> they won't get called until future is resolved. Obviously this stalls 
> permanently.
>
> Again this scenario is unlikely, but it is another indicator to me 
> that the spec is wrong (has a typo?)


In addition to the potential failure mode, *and* the lack of use-cases 
for this setting, the [DOMPromises 
polyfill](https://github.com/slightlyoff/Promises/blob/master/polyfill/src/Promise.js) 
also doesn't bind the callback to the associated future/promise (or 
anything for that matter).

Is / was there a justification for this step?

Sean
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.