Documentation

DeferredCancellation
in package
uses ForbidCloning, ForbidSerialization

FinalYes

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
see
Cancellation
see
CancelledException

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

Methods

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : never
Parameters
$data : array<string|int, mixed>
Return values
never

cancel()

public cancel([Throwable|null $previous = null ]) : void
Parameters
$previous : Throwable|null = null

Exception to be used as the previous exception to CancelledException.


        
On this page

Search results