W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2013

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

From: Sean Hogan <shogun70@westnet.com.au>
Date: Wed, 15 May 2013 23:33:59 +1000
Message-ID: <51938EC7.2070707@westnet.com.au>
To: www-dom@w3.org
CC: Anne van Kesteren <annevk@annevk.nl>
I'm perplexed by the second step of future wrapper callbacks:

Set callback's callback this value 
<http://dev.w3.org/2006/webapi/WebIDL/#dfn-callback-this-value> to 
resolver's associated future <http://dom.spec.whatwg.org/#concept-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 

Again this scenario is unlikely, but it is another indicator to me that 
the spec is wrong (has a typo?)

My first thought was that the step was supposed to read:

     Set callback's callback this value 
<http://dev.w3.org/2006/webapi/WebIDL/#dfn-callback-this-value> to 

But that doesn't make sense either because the callback is supposed to 
cause the future to be resolved by returning a value or throwing an 
error (or by returning a **separate** Future).

However, I do think this behavior would be useful.

Imagine a method of Future - say Future.prototype.whenever - which 
behaves like `then`, except that callbacks are called as:

     callback.call(resolver, value);

This would make asynchronous pipes straight-forward. I'd better give an 

     .whenever(function(value) {
         var r = this;
         setTimeout(function() {
     .whenever(function(value) {
         var r = this;
         setTimeout(function() {
             r.accept(value + 8);
     .done(function(value) {

The callbacks can behave similarly to the `init` function called from 
`new Future(init)`.
If the `init` function was also called in this way then the concept 
would be easier to grasp.
Received on Wednesday, 15 May 2013 13:34:27 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:02 UTC