numCols = $result->numCols; parent::__construct(new Producer(function (callable $emit) use ($result, $fetch) { $count = 0; try { do { $next = $fetch(); // Request next result before current is consumed. ++$count; yield $emit($result->fetchRow(pq\Result::FETCH_ASSOC)); $result = yield $next; } while ($result instanceof pq\Result); } finally { $this->complete(); } return $count; })); } public function __destruct() { parent::__destruct(); $this->release(); } public function numFields(): int { return $this->numCols; } }