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

On Thu, May 2, 2013 at 2:32 PM, Sam L'ecuyer <sam@cateches.is> wrote:
>> 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.

Almost.  The reason the third example failed is because it's a
"thenable" but not a "promise-like" - it's a false positive for the
"should I treat this like a promise?" test.

Your fourth example is an inversion of what I'm trying to say.  I want
promises to work such that:

1. A "thenable" is just treated as a plain value when returned by a
.then() callback.
2. You use Future.assimilate() or whatever to transform a
"promise-like" into a promise.

~TJ

Received on Thursday, 2 May 2013 21:43:18 UTC