Skip to content

Promises returned from generators are not resolved automatically #64

@dstillman

Description

@dstillman

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions