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

Promises returned from generators are not resolved automatically #64

Closed
dstillman opened this Issue Jan 11, 2014 · 4 comments

Comments

Projects
None yet
3 participants
@dstillman

dstillman commented Jan 11, 2014

In Q, if an async generator returns a promise, that promise is resolved and the resolved value is passed on. In Bluebird, the promise itself is passed along as the next value:

Q v1.0.0:

Q.async(function* () {
    return Promise.resolve("")
})()
.then(function (str) {
    alert(typeof str); // 'string'
})
.done();

Bluebird v0.11.6-1:

Promise.spawn(function* () {
    return Promise.resolve("");
})
.then(function (str) {
    alert(typeof str); // 'object'
});

The workaround in Bluebird is to yield on the promise before returning it:

Promise.spawn(function* () {
    return yield Promise.resolve("");
})
.then(function (str) {
    alert(typeof str); // 'string'
});

But that seems like an unnecessary extra step that could be avoided, and I think it goes against expectations coming from Promise.try(). Is this behavior intentional?

@benjamingr

This comment has been minimized.

Show comment
Hide comment
@benjamingr

benjamingr Jan 11, 2014

Collaborator

To be fair, in C# you would write return await and not return to return from an async function.

The Bluebird behavior seems nice (and correct) but I see your point - this is inconsistent with the way promises unwrap. Definitely something we need to think about.

Collaborator

benjamingr commented Jan 11, 2014

To be fair, in C# you would write return await and not return to return from an async function.

The Bluebird behavior seems nice (and correct) but I see your point - this is inconsistent with the way promises unwrap. Definitely something we need to think about.

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jan 11, 2014

Owner

Yea confirmed as bug.

Owner

petkaantonov commented Jan 11, 2014

Yea confirmed as bug.

@benjamingr

This comment has been minimized.

Show comment
Hide comment
@benjamingr

benjamingr Jan 11, 2014

Collaborator

@petkaantonov are you sure returning a promise acting like in thenables is the correct behavior?

Collaborator

benjamingr commented Jan 11, 2014

@petkaantonov are you sure returning a promise acting like in thenables is the correct behavior?

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jan 11, 2014

Owner

Yes it is always without any doubt a bug if you get a promise as a .then argument

Owner

petkaantonov commented Jan 11, 2014

Yes it is always without any doubt a bug if you get a promise as a .then argument

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