SignalCancellation
in package
implements
Cancellation
uses
ForbidCloning, ForbidSerialization
A SignalCancellation automatically requests cancellation when a given signal is received.
Table of Contents
Interfaces
- Cancellation
- Cancellations are simple objects that allow registering handlers to subscribe to cancellation requests.
Properties
- $callbackIds : array<int, string>
- $cancellation : Cancellation
Methods
- __construct() : mixed
- __destruct() : mixed
- Cancels the delay watcher.
- __serialize() : never
- __unserialize() : never
- isRequested() : bool
- Returns whether cancellation has been requested yet.
- subscribe() : string
- Subscribes a new handler to be invoked on a cancellation request.
- throwIfRequested() : void
- Throws the `CancelledException` if cancellation has been requested, otherwise does nothing.
- unsubscribe() : void
- Unsubscribes a previously registered handler.
- __clone() : mixed
Properties
$callbackIds read-only
private
array<int, string>
$callbackIds
$cancellation read-only
private
Cancellation
$cancellation
Methods
__construct()
public
__construct(int|array<string|int, int> $signals[, string $message = "Operation cancelled by signal" ]) : mixed
Parameters
- $signals : int|array<string|int, int>
-
Signal number or array of signal numbers.
- $message : string = "Operation cancelled by signal"
-
Message for SignalException. Default is "Operation cancelled by signal".
__destruct()
Cancels the delay watcher.
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
neverisRequested()
Returns whether cancellation has been requested yet.
public
isRequested() : bool
Return values
boolsubscribe()
Subscribes a new handler to be invoked on a cancellation request.
public
subscribe(Closure $callback) : string
This handler might be invoked immediately in case the cancellation has already been requested. Any unhandled exceptions will be thrown into the event loop.
Parameters
- $callback : Closure
-
Callback to be invoked on a cancellation request. Will receive a
CancelledExceptionas first argument that may be used to fail the operation.
Return values
string —Identifier that can be used to cancel the subscription.
throwIfRequested()
Throws the `CancelledException` if cancellation has been requested, otherwise does nothing.
public
throwIfRequested() : void
unsubscribe()
Unsubscribes a previously registered handler.
public
unsubscribe(string $id) : void
The handler will no longer be called as long as this method isn't invoked from a subscribed callback.
Parameters
- $id : string
__clone()
protected
final __clone() : mixed