/** * @coroutine * * @param callable $function Function name to execute. * @param mixed ...$args Arguments to pass to function. * * @return \Generator * * @resolve resource * * @throws \Icicle\Postgres\Exception\FailureException */ private function send(callable $function, ...$args) : \Generator { while (null !== $this->delayed) { try { (yield $this->delayed); } catch (\Throwable $exception) { // Ignore failure from another operation. } } $result = $function($this->handle, ...$args); if (false === $result) { throw new FailureException(\pg_last_error($this->handle)); } $this->delayed = new Delayed($this->onCancelled); $this->poll->setData($this->delayed); $this->await->setData($this->delayed); $this->poll->listen(); if (0 === $result) { $this->await->listen(); } try { $result = (yield $this->delayed); } finally { $this->delayed = null; $this->poll->cancel(); $this->await->cancel(); } return $result; }
/** * {@inheritdoc} * * @param float|int $timeout Timeout for poll if a read was pending. */ public function rebind(float $timeout = 0) { $pending = $this->poll->isPending(); $this->poll->free(); $this->poll = $this->createPoll($this->getResource(), $this->queue); if ($pending) { $this->poll->listen($timeout); } }
/** * {@inheritdoc} * * @param float|int $timeout Timeout for await if a write was pending. */ public function rebind(float $timeout = 0) { if (null !== $this->await) { $pending = $this->await->isPending(); $this->await->free(); $this->await = $this->createAwait($this->getResource(), $this->writeQueue); if ($pending) { $this->await->listen($timeout); } } }
/** * @coroutine * * @return \Generator * * @throws \Icicle\Concurrent\Exception\StatusError If the process has not been started. */ public function join() : \Generator { if (null === $this->delayed) { throw new StatusError('The process has not been started.'); } $this->poll->listen(); try { return (yield $this->delayed); } finally { $this->stdout->close(); $this->stderr->close(); } }
public function __destruct() { $this->poll->free(); }