DeferredCancellation
in package
uses
ForbidCloning, ForbidSerialization
A deferred cancellation provides a mechanism to cancel operations dynamically.
Cancellation of operation works by creating a deferred cancellation and passing the corresponding cancellation when
starting the operation. To cancel the operation, invoke DeferredCancellation::cancel().
Any operation can decide what to do on a cancellation request, it has "don't care" semantics. An operation SHOULD be aborted, but MAY continue. Example: A DNS client might continue to receive and cache the response, as the query has been sent anyway. An HTTP client would usually close a connection, but might not do so in case a response is close to be fully received to reuse the connection.
Example
$deferredCancellation = new DeferredCancellation;
$cancellation = $deferredCancellation->getCancellation();
$response = $httpClient->request("https://example.com/pipeline", $cancellation);
$responseBody = $response->getBody();
while (null !== $chunk = $response->read()) {
// consume $chunk
if ($noLongerInterested) {
$deferredCancellation->cancel();
break;
}
}
Tags
Table of Contents
Properties
- $cancellation : Cancellation
- $source : Cancellable
Methods
- __construct() : mixed
- __destruct() : mixed
- __serialize() : never
- __unserialize() : never
- cancel() : void
- getCancellation() : Cancellation
- isCancelled() : bool
- __clone() : mixed
Properties
$cancellation read-only
private
Cancellation
$cancellation
$source read-only
private
Cancellable
$source
Methods
__construct()
public
__construct() : mixed
__destruct()
public
__destruct() : mixed
__serialize()
public
final __serialize() : never
Return values
never__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : never
Parameters
- $data : array<string|int, mixed>
Return values
nevercancel()
public
cancel([Throwable|null $previous = null ]) : void
Parameters
- $previous : Throwable|null = null
-
Exception to be used as the previous exception to CancelledException.
getCancellation()
public
getCancellation() : Cancellation
Return values
CancellationisCancelled()
public
isCancelled() : bool
Return values
bool__clone()
protected
final __clone() : mixed