Amp\Mysql\ResultSet::genericFetch PHP Method

genericFetch() protected method

protected genericFetch ( callable $cb = null )
$cb callable
    protected function genericFetch(callable $cb = null)
    {
        if ($this->result->userFetched < $this->result->fetchedRows) {
            $row = $this->result->rows[$this->result->userFetched++];
            return new Success($cb ? $cb($row) : $row);
        } elseif ($this->result->state == ResultProxy::ROWS_FETCHED) {
            return new Success(null);
        } else {
            $deferred = new Deferred();
            /* We need to increment the internal counter, else the next time genericFetch is called,
             * it'll simply return the row we fetch here instead of fetching a new row
             * since callback order on promises isn't defined, we can't do this via when() */
            $incRow = function ($row) use($cb) {
                $this->result->userFetched++;
                return $cb && $row ? $cb($row) : $row;
            };
            $this->result->deferreds[ResultProxy::SINGLE_ROW_FETCH][] = [$deferred, null, $incRow];
            return $deferred->promise();
        }
    }