guzzle / promises

Promises/A+ library for PHP with synchronous support
MIT License
7.61k stars 116 forks source link

Fix manually settle promises generated with Utils::task #136

Closed edipoReboucas closed 3 years ago

edipoReboucas commented 3 years ago

Promises generated with Utils::task throw a error when they are canceled ou resolved before TaskQueue:run is called. With this behavior, we can't cancel a promise generated with Utils::task method, a useful behavior. In this fix the waitFn function generated in Utils:task is checking if promise is alredy settle, and skip the call to task function in this case.

GrahamCampbell commented 3 years ago

Won't this result in failing to reject promises that throw exceptions when resolved more than once?

edipoReboucas commented 3 years ago

I can write a test for this scenario.

If you provide a code snippet with this exact scenario, it will be very helpful.