shutdown() public method

Shuts down the pool and all workers in it.
public shutdown ( ) : Generator
return Generator
Exemplo n.º 1
0
    {
        $this->callable = $callable;
        $this->args = $args;
    }
    public function run(Environment $environment)
    {
        ($this->callable)(...$this->args);
    }
}
function wait()
{
    $sleep = rand(1, 200) / 100;
    echo "Sleep {$sleep} seconds\n";
    sleep($sleep);
    echo "Awake\n";
    return true;
}
Coroutine\create(function () {
    $pool = new DefaultPool();
    $pool->start();
    $coroutines = [];
    for ($i = 0; $i < 50; $i++) {
        $coroutines[] = Coroutine\create(function () use($pool) {
            $result = (yield from $pool->enqueue(new CallableTask('wait')));
            return $result;
        });
    }
    (yield Awaitable\all($coroutines));
    return yield from $pool->shutdown();
})->done();
Loop\run();