TaskSet::seal

(PHP 8.6+, True Async 1.0)

public TaskSet::seal(): void

Seals the set. After this, spawn() and spawnWithKey() throw an exception. Already running coroutines and queued tasks continue to work.

Repeated calls are a noop.

Examples

Example #1 Basic usage

<?php

use Async\TaskSet;

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

    $set->spawn(fn() => "task");
    $set->seal();

    try {
        $set->spawn(fn() => "another task");
    } catch (\Async\AsyncException $e) {
        echo $e->getMessage() . "\n";
        // "Cannot spawn tasks on a sealed TaskGroup"
    }
});

See Also