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