Documentation

Traverser
in package

An adapter to convert an async function into an async iterator.

The function can be written like a normal await-generator function. When yielding a value is intended, the user can run yield $value => Await::VALUE; to stop and output the value.

Table of Contents

MAX_INTERRUPTS  = 16
VALUE  = "traverse.value"
$inner  : Generator
__construct()  : mixed
collect()  : Generator
Asynchronously waits for all remaining values in the underlying iterator and collects them into a linear array.
fromClosure()  : self
interrupt()  : Generator
Throw an exception into the underlying generator repeatedly so that all `finally` blocks can get asynchronously executed.
next()  : Generator
Creates a future that starts the next iteration of the underlying coroutine, and assigns the next yielded value to `$valueRef` and returns true.

Constants

MAX_INTERRUPTS

public mixed MAX_INTERRUPTS = 16

Properties

Methods

__construct()

public __construct(Generator $inner) : mixed
Parameters
$inner : Generator
Return values
mixed

collect()

Asynchronously waits for all remaining values in the underlying iterator and collects them into a linear array.

public collect() : Generator
Return values
Generator

fromClosure()

public static fromClosure(Closure $closure) : self
Parameters
$closure : Closure
Tags
phpstan-param

Closure(): Generator $closure

Return values
self

interrupt()

Throw an exception into the underlying generator repeatedly so that all `finally` blocks can get asynchronously executed.

public interrupt([Throwable $ex = null ][, int $attempts = self::MAX_INTERRUPTS ]) : Generator

If the underlying generator throws an exception not identical to $ex, this function will return the new exceptioin. Returns null if the underlying generator successfully terminated or throws.

Throws AwaitException if $attempts throws were performed and the iterator is still executing.

All values iterated during interruption are discarded.

Parameters
$ex : Throwable = null
$attempts : int = self::MAX_INTERRUPTS
Return values
Generator

next()

Creates a future that starts the next iteration of the underlying coroutine, and assigns the next yielded value to `$valueRef` and returns true.

public next(mixed &$valueRef) : Generator

Returns false if there are no more values.

Parameters
$valueRef : mixed
Return values
Generator

Search results