TaskSet::cancel

(PHP 8.6+, True Async 1.0)

public TaskSet::cancel(?Async\AsyncCancellation $cancellation = null): void

Bricht alle laufenden Coroutinen ab und leert die Task-Warteschlange. Ruft implizit seal() auf.

Parameter

cancellation
Abbruchgrund. Wenn null, wird eine Standard-AsyncCancellation erstellt.

Beispiele

Beispiel #1 Bedingter Abbruch

<?php

use Async\TaskSet;

spawn(function() {
    $set = new TaskSet();

    $set->spawn(fn() => longRunningTask1());
    $set->spawn(fn() => longRunningTask2());

    // Alle Tasks abbrechen
    $set->cancel();

    echo $set->isSealed() ? "versiegelt\n" : "nein\n"; // "versiegelt"
});

Siehe auch