getToken(); * * $response = yield $httpClient->request("https://example.com/pipeline", $token); * $responseBody = $response->getBody(); * * while (($chunk = yield $response->read()) !== null) { * // consume $chunk * * if ($noLongerInterested) { * $cancellationTokenSource->cancel(); * break; * } * } * ``` * * @see CancellationToken * @see CancelledException */ final class CancellationTokenSource { private Internal\CancellableToken $source; private CancellationToken $token; public function __construct() { $this->source = new Internal\CancellableToken; $this->token = new Internal\WrappedCancellationToken($this->source); } public function getToken(): CancellationToken { return $this->token; } /** * @param \Throwable|null $previous Exception to be used as the previous exception to CancelledException. */ public function cancel(?\Throwable $previous = null): void { $this->source->cancel($previous); } }