A Challenge Problem for Promise Designers

Tab Atkins Jr. jackalmage at gmail.com
Mon Apr 29 13:20:14 PDT 2013

On Mon, Apr 29, 2013 at 1:07 PM, Ron Buckton <rbuckton at chronicles.org> wrote:
> I updated [1] my rough implementation of Future based on this discussion. This has the following changes from the previous [2] version which was based on the DOM spec for Future:
> * The resolver's resolve algorithm tests value to determine if it is a Future instance (rather than a "thenable"). This could later be done by checking branding or by checking for a symbol.
> * The resolver's resolve algorithm only unwraps the value once if it is a Future, rather than performing flattening. It does this by calling the resolver's accept algorithm in the "resolve" future callback for rather than the resolve algorithm.
> * In the steps for Future#then, if the "resolveCallback" is null, the "resolve" callback becomes a future callback for resolver and its accept algorithm. This is to preserve the value for something like:
>     Future.accept(Future.accept(value)).then().then(F => /* F is Future(value) */)
>     Future.accept(Future.accept(Future.accept(value))).then().then(FF => /* FF is Future(Future(value)) */)
> * In the steps for some/any/every, the future callbacks that are created that used the resolver's resolve algorithm now use the resolver's accept algorithm. This is to preserve the value for something like:
>     Future.any(Future.accept(Future.accept(value))).then(F => /* F is Future(value) */)
>     Future.any(Future.accept(Future.accept(Future.accept(value)))).then(FF => /* FF is Future(Future(value)) */)

This all sounds right.

> * Added Future.from to perform explicit assimilation (with only one level of unwrap, as with Future#then)

Like I said, Domenic says that recursive assimilation is useful, and
I'm inclined to believe him, as he has a lot more experience in
getting arbitrary thenables to play nicely together than I do. ^_^

> * Added Future.isFuture to test for native Futures

For the purpose of library code, you don't need this - just use "x
instanceof Future".  Future.isFuture is only useful for the language
to define, so that it can tell something is a Future cross-frame.


More information about the es-discuss mailing list