context = $context; } /** * {@inheritdoc} */ public function isRunning() { return $this->context->isRunning(); } /** * {@inheritdoc} */ public function isIdle() { return $this->idle; } /** * {@inheritdoc} */ public function start() { $this->context->start(); } /** * {@inheritdoc} */ public function kill() { $this->context->kill(); } /** * {@inheritdoc} */ public function shutdown() { yield $this->context->send([null, []]); yield $this->context->join(); } /** * {@inheritdoc} */ public function enqueue(TaskInterface $task /* , ...$args */) { if (!$this->context->isRunning()) { throw new SynchronizationError('Worker has not been started.'); } $args = array_slice(func_get_args(), 1); yield $this->context->send([$task, $args]); $this->idle = false; $result = (yield $this->context->receive()); $this->idle = true; if ($result instanceof TaskFailure) { //throw $result->getException(); } yield $result; } }