sleep()

/**
 * @throws Throwable
 */
public static function sleep(string $name, int $seconds): void;

This is the static method that will allow that flow to stop executing for a period of time measured in seconds.

Example:

function thread (string $thread, int $loop) {
    $i = $loop;
    while ($i--)
    {
        var_dump("Thread '{$thread}' printing '{$thread}' for {$i} times!");
        GreenThread::sleep($thread, 1); // It will sleep in 1 second
    }
    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