Promise.cast and Promise.resolve

Paolo Amadini paolo.02.prg at
Wed Jan 29 04:44:33 PST 2014

While the getMyPromise question wasn't answered yet and still isn't
clear to me, from the other posts I think it can be reworded this way:

var p1 = Promise.resolve(Promise.cast(1));
var p2 = Promise.cast(Promise.cast(1));

p1 and p2 will have a different internal state, but there is no way to
tell the difference between the two (and no way to write a regression
test to check that the internal state is correct), until in the future
a new method will be defined.

Is this correct? What about the case of:

var p3 = new Promise(resolve => resolve(Promise.cast(1));

Will the state of p3 be more similar to that of p1 or that of p2?

I'll file a bug when I understand the situation better.


On 28/01/2014 21.07, Paolo Amadini wrote:
> I don't have a background on the .flatMap level of abstraction. In the
> following scenario, will users of getMyPromise() have a different
> behavior with .flatMap if the library code used "cast" rather than
> "resolve"? If so, this can definitely lead to confusion when .flatMap
> is introduced in the future since the callers cannot be sure about
> what the library did internally, assuming the library authors didn't
> intentionally choose one or the other.
> ```js
> // ------ MyLibrary.js
> function getMyPromise() {
>   var a = condition ? getMyOtherPromise() : "value2";
>   return Promise.resolve(a);
> }
> function getMyOtherPromise() {
>   return Promise.resolve("value1");
> }
> ```

More information about the es-discuss mailing list