channel = $channel; $this->environment = $environment; } /** * @coroutine * * @return \Generator */ public function run() { $task = (yield $this->channel->receive()); while ($task instanceof TaskInterface) { $this->idle = false; try { $result = (yield $task->run($this->environment)); } catch (\Exception $exception) { $result = new TaskFailure($exception); } yield $this->channel->send($result); $this->idle = true; $task = (yield $this->channel->receive()); } yield $task; } /** * @return bool */ public function isIdle() { return $this->idle; } }