Icicle\Concurrent\Worker\DefaultPool::enqueue PHP Метод

enqueue() публичный Метод

Enqueues a task to be executed by the worker pool.
public enqueue ( Icicle\Concurrent\Worker\Task $task ) : Generator
$task Icicle\Concurrent\Worker\Task The task to enqueue.
Результат Generator
    public function enqueue(Task $task) : \Generator
    {
        $worker = $this->get();
        return yield from $worker->enqueue($task);
    }

Usage Example

Пример #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();
All Usage Examples Of Icicle\Concurrent\Worker\DefaultPool::enqueue