Skip to content

[HttpClient] add ResponseSetMonitor to trigger callbacks on response completion #32174

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

Closed
wants to merge 2 commits into from

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jun 25, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets Fix #32142
License MIT
Doc PR -

Related to #32367

Follows some discussions on Slack+Github: how do we trigger callbacks when responses complete?
Here is a quick poc doing so:

$client = HttpClient::create();
$monitor = new ResponseSetMonitor($client);
$monitor->add($client->request(...), $onHeaders, $onBody, $onError);
// [...]
$monitor->tick(); // non-blocking call
// [...]
$monitor->tick(0.001); // don't make the tick last more than 1ms
// [...]
$monitor->complete(); // complete responses and consider timeouts as errors
// [...]
$monitor->cancel() // cancel all pending responses - usually run after a ->tick($someTimeout)

Of course, since there is no event loop under the hood, one still needs to "tick" to move the network read/writes forward.

Useful in the component? If you think so I'd happily accept a PR that adds tests on top :)

@nicolas-grekas nicolas-grekas added this to the next milestone Jun 25, 2019
@nicolas-grekas nicolas-grekas changed the title [HttpClient] add ResponseMonitor to trigger callbacks on response completion [HttpClient] add ResponseSetMonitor to trigger callbacks on response completion Jun 25, 2019
@nicolas-grekas
Copy link
Member Author

#33743 will provide a better abstraction and #32367 is here to keep track of a lower level / native implementation.

@nicolas-grekas nicolas-grekas deleted the hc-monitor branch October 4, 2019 18:06
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpClient] Getting responses asynchronously as soon as they ready
3 participants