register()

/**
 * @param string|int $name
 * @param callable $callback
 * @param array<int, mixed> $params
 *
 * This method is used to register a green thread.
 */
public static function register(string|int $name, callable $callback, array $params): void;

This is the static method used to register a child flow.

Example:

function thread (string $thread, int $loop) {
    $i = $loop;
    while ($i--)
    {
        var_dump("Thread '{$thread}' printing '{$thread}' for {$i} times!");
    }
    var_dump("Thread '{$thread}' finished after printing '{$thread}' for {$loop} times!");
}

foreach(range('A', 'F') as $c) {
    GreenThread::register($c, 'thread', [$c, rand(5, 20)]);
}

Last updated