TaskSet::cancel
(PHP 8.6+, True Async 1.0)
php
public TaskSet::cancel(?Async\AsyncCancellation $cancellation = null): voidCancels all running coroutines and clears the task queue. Implicitly calls seal().
Parameters
cancellation : Cancellation reason. If null, a default AsyncCancellation is created.
Examples
Example #1 Conditional cancellation
php
<?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