/** * {@inheritdoc} */ public function send($data) : \Generator { if (null === $this->channel) { throw new StatusError('The process has not been started.'); } if ($data instanceof ExitStatus) { throw new InvalidArgumentError('Cannot send exit status objects.'); } return yield from $this->channel->send($data); }
/** * @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; }
/** * {@inheritdoc} */ public function send($data) { if (null === $this->channel) { throw new StatusError('The process has not been started.'); } if ($data instanceof ExitStatusInterface) { throw new InvalidArgumentError('Cannot send exit status objects.'); } yield $this->channel->send($data); }
exit(1); } require $autoloadPath; use Icicle\Concurrent\Sync\Channel; use Icicle\Concurrent\Sync\Internal\ExitFailure; use Icicle\Concurrent\Sync\Internal\ExitSuccess; use Icicle\Concurrent\Worker\Environment; use Icicle\Concurrent\Worker\Internal\TaskRunner; use Icicle\Coroutine; use Icicle\Loop; use Icicle\Stream; Coroutine\create(function () { $channel = new Channel(Stream\stdin(), Stream\stdout()); $environment = new Environment(); $runner = new TaskRunner($channel, $environment); try { $result = new ExitSuccess(yield $runner->run()); } catch (Exception $exception) { $result = new ExitFailure($exception); } yield $channel->send($result); })->done(); Loop\run();