Replies: 1 comment
-
I found the solution to my problem. My solution was entirely wrong. I had to go so deep inside the library to find the solution 😱 . But here it is: $foo = new class {
private $response;
private $buffer = '';
private $cancel;
public function request() {
$client = (new HttpClientBuilder)->build();
$request = new Request('https://127.0.0.1/acme', 'GET');
$request->setInactivityTimeout(60);
$request->setTransferTimeout(60);
$request->setTcpConnectTimeout(60);
$this->cancel = new DeferredCancellation();
$this->response = $client->request($request, $this->cancel->getCancellation());
try {
while (null !== $chunk = $this->response->getBody()->read()) {
$this->buffer .= $chunk;
echo "Received: \n$chunk\n";
}
} catch (CancelledException) {
echo "Cancelled\n";
}
}
public function stop() {
$this->cancel->cancel();
}
}
await([
async(function () use ($foo) {
$foo->request();
}),
async(function () use($foo) {
delay(10); // Of course imagine something else here than the delay
$foo->stop();
})
]);
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have the following code:
Doing this results in the following error:
Is there any best way to stop the connection without getting such an error?
By the way... This exception does not seem possible to be caught.
Beta Was this translation helpful? Give feedback.
All reactions