Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaining promises in version 7+ #93

Closed
danamajid opened this issue Apr 30, 2015 · 14 comments
Closed

Chaining promises in version 7+ #93

danamajid opened this issue Apr 30, 2015 · 14 comments

Comments

@danamajid
Copy link

I'm trying to just do a simple chaining of promises, by first pushing promises to an array and then do Promise.all(array).then(function(results) { console.log(results); }). This used to work just fine in v6.x, but since upgrading to the latest version, it fails.

At the essence, what seems to differ from before is:

console.log(new Promise(function (resolve, reject) {
  resolve();
}));

Previously this would log: { then: [Function] }

Now on version 7.0.1, this results in: { _32: 0, _8: null, _89: [] }

Did I miss a change in API or am I messing things up? :)

@samuelbeek
Copy link

+1

1 similar comment
@kayvink
Copy link

kayvink commented Apr 30, 2015

+1

@ForbesLindesay
Copy link
Member

then is now on the prototype. What this means is that you can no longer do:

var promise = new Promise(function (resolve) {
  resolve();
});
var then = promise.then;
then(function () {}); // this won't work
promise.then(function () {}); // but this would work fine

If you can produce an example of code that fails, I'd be very happy to look into why it fails.

@danamajid
Copy link
Author

Thanks, that did the trick.

For future readers: in order to do Promise.all(promisesArray), the promisesArray should look like: [promiseA.then(), promiseB.then()] and not [promiseA, promiseB] like before.

@ForbesLindesay
Copy link
Member

no, there should be no need to do that.

@ForbesLindesay
Copy link
Member

If you could provide an example that demonstrates the failure, it would be incredibly helpful.

@ForbesLindesay
Copy link
Member

Could you tell me what exactly the failure is when you do Promise.all(array).then(function(results) { console.log(results); })? Do you get an exception? Does it just never resolve?

@danamajid
Copy link
Author

No exception and it just never resolves. Just wrote a reduced version but that works like you said – so something else must be causing it.. So I am separating things now to find out. Stay tuned.

@ForbesLindesay
Copy link
Member

Are you interacting with any other promise libraries? Especially libraries like lazy-promise (which inherit from promise as a base class)?

@danamajid
Copy link
Author

No. Only thing out of the ordinary is that its populating the array inside multiparty's form.on('part').

Can't reproduce a test case right now and have to run. Either way, think it's unrelated to this lib. Feel free to close the issue. Thanks for your help!

@ForbesLindesay
Copy link
Member

OK, please post here when you manage to produce a test case. @samuelbeek & @kayvink perhaps one of you can produce an example?

If all the promises were Promises/A+ compliant, then there is a bug in this library so I'd very much like to get to the bottom of it.

@samuelbeek
Copy link

@ForbesLindesay unfortunately not, because @danamajid fixed the problem for me too (since we work together).

@ForbesLindesay
Copy link
Member

It turns out this is (see #99) caused by asap sometimes calling back twice and sometimes not at all. The offending issue is kriskowal/asap#55, which has now been resolved. Updating asap should be sufficient, which should happen automatically if you delete any caches and re-install.

I will release an update of promise that requires the latest version of asap though to encourage people to update faster.

@edef1c
Copy link
Member

edef1c commented Aug 2, 2015

Closing this, given that [email protected] resolves this.

@edef1c edef1c closed this as completed Aug 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants