Closed Sammyjo20 closed 1 year ago
I also wanted to prove that it's still wrapping the inner promise as I expect, so I added three dumps - one inside a Guzzle middleware, one inside of Saloon's request middleware and one inside Saloon's response middleware and the output is like this:
Note This is sending 100 requests with a concurrency of 10
Previous Output (Before Fix)
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
Output With Fix
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"Send!" // tests/Feature/ExampleTest.php:37
"Send Guzzle!" // tests/Feature/ExampleTest.php:30
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
"response" // tests/Feature/ExampleTest.php:41
I think I cracked it! 🤠🚀 This fixes a very tricky issue to get around raised in #306
So it turns out that the way I wrote the promise wrapping before, meant that the Pool was only sending the outer promise in the concurrency specified, and the inner promise would just be invoked synchronously. After spending the last couple of nights learning properly how Guzzle's promise library works, and looking through hundreds of lines of code - I managed to stumble across our golden method.
Utils::task()
.As described in the docs this method:
Looking at the code:
It's exactly what we need!
HUGE thanks to @aidan-casey for spending his Friday night looking at this issue - and helping me get to the bottom of it.