WyriHaximus · GitHub

Copy link Copy Markdown

Member

This is a backport from #33.

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.

Read the original on github.com ↗