-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Getting responses asynchronously as soon as they ready #32142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for sharing your use case. In the doc, I tried to explain what the contracts provide to fit this use case: This allows building what you're describing without much complexity. Can you figure out how? |
So, it seems that there is no way to achieve this without interrupting main program flow for this (you have to switch to that foreach cycle, and be there until the very last request is finished). I just thought it might be possible to get it somehow out of But it seems that at some point I have to switch to analyzing all responses, maybe on kernel exception event, currently I do it on kernel terminate event. |
Somehow :) |
Will be fixed by #33743 |
…() (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()
Here is the deal: I use Symfony and HttpClient in telegram bot. Bot sends various requests to Telegram's API, and most of these I don't really care to get the response in main bot logic (I want to run the code as fast as possible). However, I'd like to add requests and responses to Sentry breadcrumbs for reporting. Adding requests is easy. Adding responses is tricky.
I don't want actually to call
Response->getContent()
, so that it would stop main logic execution until I get the response. However, I'd like to somehow get notified as soon as response is ready. Then, I'd like to add the response to breadcrumbs, and then if there were errors in responses - send a notification.I've tried subscribing to
on_progress
, but that didn't work, since responses were not ready when I tried using them from that callback.So, I couldn't find anything about some sort of event system, so that I could subscribe and get responses as soon as they get ready. Is it really possible? And if not, then it's a feature request, I guess...
The text was updated successfully, but these errors were encountered: