TaskSet::cancel
(PHP 8.6+, True Async 1.0)
public TaskSet::cancel(?Async\AsyncCancellation $cancellation = null): void
Cancels all running coroutines and clears the task queue.
Implicitly calls seal().
Parameters
- cancellation
- Cancellation reason. If
null, a defaultAsyncCancellationis created.
Examples
Example #1 Conditional cancellation
<?php
use Async\TaskSet;
spawn(function() {
$set = new TaskSet();
$set->spawn(fn() => longRunningTask1());
$set->spawn(fn() => longRunningTask2());
// Cancel all tasks
$set->cancel();
echo $set->isSealed() ? "sealed\n" : "no\n"; // "sealed"
});
See Also
- TaskSet::seal — Seal the set
- TaskSet::dispose — Destroy the set scope