Page MenuHomePhabricator
Diviner libphutil Tech Docs LinesOfALargeExecFuture

final class LinesOfALargeExecFuture
libphutil Technical Documentation (Filesystem)

Read the output stream of an ExecFuture one line at a time. This abstraction allows you to process large inputs without holding them in memory. If you know your inputs fit in memory, it is generally more efficient (and certainly simpler) to read the entire input and explode() it. For more information, see LinesOfALarge. See also LinesOfALargeFile for a similar abstraction that works on files.

$future = new ExecFuture('hg log ...');
foreach (new LinesOfALargeExecFuture($future) as $line) {
  // ...
}

If the subprocess exits with an error, a CommandException will be thrown.

On destruction, this class terminates the subprocess if it has not already exited.

Tasks

Construction

  • public function __construct($future) — To construct, pass an @{class:ExecFuture}.

Internals

  • public function __destruct() — On destruction, we terminate the subprocess if it hasn't exited already.
  • protected function willRewind() — The PHP `foreach()` construct calls rewind() once, so we allow the first `rewind()`, without effect. Subsequent rewinds mean misuse.
  • protected function readMore() — Read more data from the subprocess.

Methods

public function __construct($future)

To construct, pass an ExecFuture.

Parameters
ExecFuture$futureFuture to wrap.
Return
this//Implicit.//

public function __destruct()

On destruction, we terminate the subprocess if it hasn't exited already.

Return
void

protected function willRewind()

The PHP foreach() construct calls rewind() once, so we allow the first rewind(), without effect. Subsequent rewinds mean misuse.

Return
void

protected function readMore()

Read more data from the subprocess.

Return
stringBytes read from stdout.