Skip to content

Add Generator-based coroutine() function #12

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

Merged
merged 1 commit into from
Nov 18, 2021

Conversation

clue
Copy link
Member

@clue clue commented Nov 18, 2021

This changeset adds a Generator-based coroutine() function for the upcoming v3 release.

The API integrates nicely with existing Promise-based APIs and can be used to execute a Generator-based coroutine to "await" promises. Using Generator-based coroutines is an alternative to directly using the underlying promise APIs. For many use cases, this makes using promise-based APIs much simpler, as it resembles a synchronous code flow more closely.

A somewhat similar solution has been provided by @recoilphp for years already (big shout out!). After discussing this both internally and with Recoil (hey @jmalloc 👋), I think we all agree that having this as a first-class citizen in the ReactPHP ecosystem would be a fantastic opportunity!

I hear there are more news to follow soon with the imminent PHP 8.1 release, but in either case I still think this function provides a very nice integration point and also migration path towards the future of using promises! (More on that in a follow-up PR 🤫)

Builds on top of #11

@clue clue added the new feature New feature or request label Nov 18, 2021
@clue clue added this to the v3.0.0 milestone Nov 18, 2021
@clue clue requested a review from WyriHaximus November 18, 2021 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants