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

co handling of return value #298

Open
jakwuh opened this issue Sep 29, 2016 · 5 comments
Open

co handling of return value #298

jakwuh opened this issue Sep 29, 2016 · 5 comments

Comments

@jakwuh
Copy link

jakwuh commented Sep 29, 2016

I wonder why co yields return value by default.
This is an example:

co(function *asyncFn() {
    let browser = yield someAsyncOperation();
    return browser;
}).then(browser => browser.exit());

In the case when browser object has then method, co tries to resolve it, but I (obviously in this case) do not want such a behaviour. I know that co simply passes return value to Promise resolve callback, but implementation can be changed if needed.

Basically, I want to decide on my own if I need the returned value to be resolved as a promise. This could be achieved with such a syntax:

return browser; // simply return what I requested to, no resolving
return yield browser; // resolve browser as a promise and return it

Will be very thankful for any feedback on this issue.

@jakwuh
Copy link
Author

jakwuh commented Sep 29, 2016

@tj your short answer would be highly relevant.

@DeShadow
Copy link

return yield browser is not possible to detect. Because JS interpretation will be like:
return (yield browser)
or the same

let result = yield browser;
return result;

@jakwuh
Copy link
Author

jakwuh commented Oct 13, 2016

@DeShadow you've misunderstood me. I was talking about returning thenable object without trying to resolve it.

@DeShadow
Copy link

@jakwuh I understand. I try to say that it's not possible. Because co can't know is construction return val or return yield val.

You can write return { browser }, but co* also check all properties of returned object and wait to Promise.all() of them.

I don't know, how to help you :(

@jakwuh
Copy link
Author

jakwuh commented Oct 14, 2016

@DeShadow I got you. Seems like this is the only possible solution for now. Thank you for the response.

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

2 participants