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

Promise.coroutine documentation #1426

Open
liushigit opened this issue Jul 23, 2017 · 7 comments
Open

Promise.coroutine documentation #1426

liushigit opened this issue Jul 23, 2017 · 7 comments
Labels

Comments

@liushigit
Copy link

liushigit commented Jul 23, 2017

I was confused by the doc for the coroutine method, which says the method

Returns a function that can use yield to yield promises.

My understanding of this wording is that, this method "returns a function that may (or may not) yield promises".

But in the provided code example, the returned function is only used as a plain function. There's no "yielded promises" from that function. If this is the example for the "may not" case, shall there be an example for the other case?

What I expected was something like

iter = a.ping()
promise = iter.next().value
@benjamingr
Copy link
Collaborator

Yeah that documentation is silly. It takes a function that can use yield to yield promises and returns a promise returning function.

A PR would be welcome

@liushigit
Copy link
Author

liushigit commented Jul 24, 2017

Here's the coroutine method's source code.

The first sentence may be changed to "Takes a GeneratorFunction producing a generator that yields promise(s), and returns a Promise returning function."

The returned Promise is defined at this line. This promise seems resolved by the value yielded by the generator (see here). If I understand it. (No. see the discussion)

@benjamingr
Copy link
Collaborator

@liushigit I'll clarify, I agree that the docs are confusing (and wrong), and if you want to submit a pull request I promise to review it and merge it.

liushigit added a commit to liushigit/bluebird that referenced this issue Jul 24, 2017
This is for this [issue](petkaantonov#1426)

TODO: The `Promise` by the function returned by the `coroutine` method needs further explanation. A thorough understanding of [the code](https://github.com/petkaantonov/bluebird/blob/4f9093448f55ea76d5a8e090e42fe24b8e0da82c/src/generators.js#L191) is needed.
@liushigit
Copy link
Author

@benjamingr A PR is added, but I have difficulty explaining the Promise returned by the function returned.

@benjamingr
Copy link
Collaborator

@liushigit thanks! I've added some suggestions, LMK what you think

@perrin4869
Copy link

I'm not sure if this is the right place to ask this question, but what's the difference performance-wise or other, between using coroutines and async/await in node >= 8? Maybe a note should be added to the documentation about it?

@benjamingr
Copy link
Collaborator

@perrin4869 it's likely async/await is still slower than Promise.coroutine at the moment. You can run the bluebird doxbee benchmarks yourself.

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

No branches or pull requests

4 participants