Page MenuHomePhabricator
Diviner libphutil Tech Docs PhutilBufferedIterator

abstract class PhutilBufferedIterator
libphutil Technical Documentation (Core Utilities)

Simple iterator that loads results page-by-page and handles buffering. In particular, this maps well to iterators that load database results page by page and allows you to implement an iterator over a large result set without needing to hold the entire set in memory.

For an example implementation, see PhutilExampleBufferedIterator.

Tasks

Methods to Implement

  • abstract protected function didRewind() — Called when @{method:rewind} is invoked. You should reset any internal cursor your implementation holds.
  • abstract protected function loadPage() — Called when the iterator needs a page of results. You should load the next result page and update your internal cursor to point past it.

Configuration

  • final public function getPageSize() — Get the configured page size.
  • final public function setPageSize($size) — Configure the page size. Note that implementations may ignore this.

Iterator Implementation

  • final public function rewind()
  • final public function valid()
  • final public function current()
  • public function key() — By default, the iterator assigns a "natural" key (0, 1, 2, ...) to each result. This method is intentionally nonfinal so you can substitute a different behavior by overriding it if you prefer.
  • final public function next()

Methods

abstract protected function didRewind()

Called when rewind() is invoked. You should reset any internal cursor your implementation holds.

Return
void

abstract protected function loadPage()

Called when the iterator needs a page of results. You should load the next result page and update your internal cursor to point past it.

If possible, you should use getPageSize() to choose a page size.

Return
list<wild>List of results.

final public function getPageSize()

Get the configured page size.

Return
intPage size.

final public function setPageSize($size)

Configure the page size. Note that implementations may ignore this.

Parameters
int$sizePage size.
Return
this

final public function rewind()

This method is not documented.
Return
wild

final public function valid()

This method is not documented.
Return
wild

final public function current()

This method is not documented.
Return
wild

public function key()

By default, the iterator assigns a "natural" key (0, 1, 2, ...) to each result. This method is intentionally nonfinal so you can substitute a different behavior by overriding it if you prefer.

Return
scalarKey for the current result (as per @{method:current}).

final public function next()

This method is not documented.
Return
wild