[HttpClient] add ResponseSetMonitor to trigger callbacks on response completion #32174
Follows some discussions on Slack+Github: how do we trigger callbacks when responses complete?
$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 :)