HH\AsyncGenerator
Async generators are similar to PHP Generators, except that we are combining async with generators
An async generator is just like a normal generator with the addition of
allowing await
statements in it because getting to the next yielded value
involves getting and awaiting on an Awaitable
.
WHILE THIS CLASS EXPOSES 3 METHODS, 99.9% OF THE TIME YOU WILL NOT USE THIS
CLASS DIRECTLY. INSTEAD, YOU WILL USE await as
IN THE CODE USING YOUR
ASYNC GENERATOR. PLEASE READ THE GUIDE REFERENCED IN THIS API DOCUMENTATION
FOR MORE INFORMATION. However, we document these methods for completeness in
case you have a use case for them.
There are three type parameters associated with an AsyncGenerator:
Tk
: The type of key returned by the generatorTv
: The type of value returned by the generatorTs
: The type that will be passed on a call tosend()
Guide
Interface Synopsis
namespace HH;
final class AsyncGenerator implements AsyncKeyedIterator<Tk, Tv> {...}
Public Methods
->next(): Awaitable<?(Tk, Tv)>
Return theAwaitable
associated with the next key/value tuple in the async generator, ornull
->raise(\Exception $exception): Awaitable<?(Tk, Tv)>
Raise an exception to the async generator->send(?Ts $value): Awaitable<?(Tk, Tv)>
Send a value to the async generator and resumes execution of the generator