Skip to content

Conversation

@SimonFrings
Copy link
Member

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 calling await(). The loop would be stopped even tho await() 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.

@SimonFrings SimonFrings changed the title [3.x] Only stop loop if a penidng promise resolves/rejects [3.x] Only stop loop if a pending promise resolves/rejects Feb 24, 2022
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonFrings Thanks for looking into this, changes LGTM! :shipit:

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? 👍

@clue clue added the new feature New feature or request label Mar 17, 2022
@clue clue added this to the v3.0.0 milestone Mar 17, 2022
@clue clue merged commit 19998f8 into reactphp:3.x Mar 17, 2022
@SimonFrings
Copy link
Member Author

Do you plan to also backport these changes to the 2.x branch? 👍

@clue Yes I will!

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.

3 participants