You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #33944 [HttpClient] resolve promise chains on HttplugClient::wait() (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[HttpClient] resolve promise chains on HttplugClient::wait()
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets | Fix#32142
| License | MIT
| Doc PR | -
Follow up of #33743
Right now, keeping a reference to promise objects returned by `HttplugClient::sendAsyncRequest()`, then calling their `wait()` method is the only way to actually resolve the promises. That's why when these promises are destructed, we cancel the corresponding HTTP request.
But thanks to the `HttplugClient::wait()` method, we have a hook to tick the event loop managed by the Symfony client.
I added a test case to run into this situation.
~It fails currently. I'd like asking @joelwurtz, @dbu and/or maybe @Nyholm if you could have a look and finish this PR? I'm not that familiar with promises and you might get faster and better to the goal. Anyone else is welcome also of course. Thank you for having a look :) PR welcome on my fork or as a separate one on this repos.~
Commits
-------
ea0be07 [HttpClient] resolve promise chains on HttplugClient::wait()
$this->promisePool = \function_exists('GuzzleHttp\Promise\queue') ? new \SplObjectStorage() : null;
72
71
73
-
if (null !== $this->responseFactory && null !== $this->streamFactory) {
74
-
return;
75
-
}
72
+
if (null === $this->responseFactory || null === $this->streamFactory) {
73
+
if (!class_exists(Psr17Factory::class)) {
74
+
thrownew \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
75
+
}
76
76
77
-
if (!class_exists(Psr17Factory::class)) {
78
-
thrownew \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
thrownew \LogicException(sprintf('You cannot use "%s()" as the "guzzlehttp/promises" package is not installed. Try running "composer require guzzlehttp/promises".', __METHOD__));
107
106
}
108
107
@@ -112,88 +111,30 @@ public function sendAsyncRequest(RequestInterface $request): Promise
112
111
returnnewRejectedPromise($e);
113
112
}
114
113
115
-
$cancel = function () use ($response) {
116
-
$response->cancel();
117
-
unset($this->promisePool[$response]);
118
-
};
114
+
$waitLoop = $this->waitLoop;
119
115
120
-
$promise = newGuzzlePromise(function () use ($response) {
121
-
$this->pendingResponse = $response;
122
-
$this->wait();
123
-
}, $cancel);
116
+
$promise = newGuzzlePromise(staticfunction () use ($response, $waitLoop) {
117
+
$waitLoop->wait($response);
118
+
}, staticfunction () use ($response, $promisePool) {
0 commit comments