W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: Promises: Auto-assimilating thenables returned by .then() callbacks: yay/nay?

From: Sam L'ecuyer <sam@cateches.is>
Date: Thu, 2 May 2013 17:32:48 -0400 (EDT)
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: "Domenic Denicola" <domenic@domenicdenicola.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <1367530368.683119775@apps.rackspace.com>

> What I'm hoping for is an explanation of why assimilating thenables is
> necessary in the .then() callbacks, and why my concerns about
> predictability (such as returning an object which has a .then()
> method, but is not a promise-like, which "assimilates" with
> non-sensical behavior and possibly causes errors) are either unfounded
> or less important than the benefits of auto-assimilation.

I think auto-assimilation is more accurately "auto-assuming".
The issue you're trying to overcome is that we attempt to unwrap the return value from a callback if it seems promise-like. 

doStuff().then(function(x) {
  return 5;
}).then(function(y) {
  //y is 5
});

doStuff().then(function(x) {
  return Future.accept(5);
}).then(function(y) {
  //y is 5
});

doStuff().then(function(x) {
  return {then: function(){ return "uh-oh"}};
}).then(function(y) {
  // the unwrap assuredly failed
});


What you want is:

doStuff().then(function(x) {
  return Future.assimilate({then: function(){ return "uh-oh"}});
}).then(function(y) {
  // y is {then: function(){ return "uh-oh"}}
});

Correct me if any of that's wrong.  Seems reasonable to me.

-s
Received on Thursday, 2 May 2013 21:33:15 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:49 UTC