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

Resolving promises with promises #48

Closed
molnarg opened this issue Jul 24, 2012 · 5 comments
Closed

Resolving promises with promises #48

molnarg opened this issue Jul 24, 2012 · 5 comments
Milestone

Comments

@molnarg
Copy link

molnarg commented Jul 24, 2012

when.js does have a strange bug when resolving a promise with an other promise. Consider this code:

var when = require('when')

var a = when.defer()
  , b = when.defer()
  , c = when.defer()

a.name = 'A'
b.name = 'B'
c.name = 'C'

// 1) without when()
// a.then(function(resolved) {
// 2) with when()
when(a).then(function(resolved) {
  console.log('A resolved into', resolved.name)
})

a.resolve(b)
b.resolve(c)
c.resolve({name : 'D'})

This (second) variant prints A resolved into C. If you switch to the first variant, it prints A resolved into B.

The two variants are supposed to be equivalent aren't they?

@briancavalier
Copy link
Member

Hey, @molnarg, when.js 1.3.0 doesn't support resolving one promise with another. However, this is implemented in the dev branch ... see #40 for more info. It'll be released soon!

@molnarg
Copy link
Author

molnarg commented Jul 24, 2012

Thanks for the reference, I will check it out!

But I believe it is a separate issue. You write in the other ticket 'Currently, when.js will use whatever you pass to resolve() verbatim as the resolution value'. This is exactly what I expect in the example above, but something goes wrong.

If I understand the when function correctly, when(promise).then and promise.then should behave exactly the same way no matter what the resolved value will be, right? And this is not the case when you run the example above.

@briancavalier
Copy link
Member

Yep, there is definitely weirdness in the current release. I tried your example in the dev branch, though, and it appears to work correctly. Please give it a try as well and let me know if you see the same. If not, I'll dig in deeper to figure it out before the next release.

If it looks good then expect a new release very soon. Thanks!

@briancavalier
Copy link
Member

Just released 1.4.0 which adds support for resolving a deferred promise with another promise, and fixes the inconsistency here. Feel free to reopen this if you find any problems with it.

@molnarg
Copy link
Author

molnarg commented Jul 31, 2012

Thank you for the hard work! :) I will check it out soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants