[3.x] Only stop loop if a pending promise resolves/rejects#33
Merged
clue merged 1 commit intoreactphp:3.xfrom Mar 17, 2022
Merged
[3.x] Only stop loop if a pending promise resolves/rejects#33clue merged 1 commit intoreactphp:3.xfrom
clue merged 1 commit intoreactphp:3.xfrom
Conversation
b139a88 to
7815f51
Compare
7815f51 to
42d343b
Compare
WyriHaximus
approved these changes
Mar 14, 2022
clue
approved these changes
Mar 17, 2022
Member
clue
left a comment
There was a problem hiding this comment.
@SimonFrings Thanks for looking into this, changes LGTM! ![]()
Discussed this feature a couple of times off-channel and I think we all agree that the await() function is only really fully usable as of v4 (#15) and every earlier usage is easily "a hot mess already". I agree this changeset makes sense for a limited number of use cases, for example a limited fiber compatibility mode as implemented in clue/framework-x#128. It's also nice how this mimics the optimizations originally planned in #22 and #18.
Do you plan to also backport these changes to the 2.x branch? 👍
Member
Author
@clue Yes I will! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If
await()is called and the promise is still pending, it will run the loop and stops it afterwards when the promise resolves/rejects. Without these changes the same thing (only stopping the loop) applies for already resolved promises when callingawait(). The loop would be stopped even thoawait()never started the loop. This could lead to unwanted behavior (e.g. if there are still operations left that need the loop).Be aware that if a pending promise resolves, and
await()stops the loop, every other operation depending on the loop won't be executed. You need to (re)start the loop manually if you want the remaining operations to finish. This behavior only occurs in v2.x and v3.x of async. I would highly recommend to use v4.x with Fibers (PHP>=8.1) to prevent unwanted behavior like this.Builds on top of #22.