Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds optional support for coroutine return values.
If the coroutine was constructed with a new
coroutine.NewWithReturn(func () R)
constructor, the return value can be retrieved using:The reason we haven't added support for passing arguments to coroutines is because it's easy to pass in data using a closure. On the other hand, getting data out of coroutines has so far been problematic. Although you can create a final yield point to pass return values out of the coroutine, the issue in #84 arises.
This PR provides a native way to get data out of a coroutine, so that you don't have to manually create a final yield point.
To keep things simple, I chose to reuse the yield type
R
rather than introduce a new generic type parameter for the return value.