diff --git a/lib/NullCancellationToken.php b/lib/NullCancellationToken.php new file mode 100644 index 0000000..170ec12 --- /dev/null +++ b/lib/NullCancellationToken.php @@ -0,0 +1,48 @@ +throwIfRequested(); + * } + * ``` + * + * potentially multiple times, it allows writing + * + * ```php + * $token = $token ?? new NullCancellationToken; + * + * // ... + * + * $token->throwIfRequested(); + * ``` + * + * instead. + */ +class NullCancellationToken implements CancellationToken { + /** @inheritdoc */ + public function subscribe(callable $callback): string { + return "null-token"; + } + + /** @inheritdoc */ + public function unsubscribe(string $id) { + // nothing to do + } + + /** @inheritdoc */ + public function isRequested(): bool { + return false; + } + + /** @inheritdoc */ + public function throwIfRequested() { + // nothing to do + } +}