TaskSet::seal

(PHP 8.6+, True Async 1.0)

public TaskSet::seal(): void

Sella el conjunto. Después de esto, spawn() y spawnWithKey() lanzan una excepción. Las coroutines en ejecución y las tareas en cola continúan funcionando.

Las llamadas repetidas no tienen efecto.

Ejemplos

Ejemplo #1 Uso básico

<?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"
    }
});

Ver también