Continuations ¶
Continuations provide an easy way to implement iterators without the complexity of implementing Iteratorinterface.
Continuations are used in generator functions. They represent types that can be used with the PHP yield keyword. A function that is a continuation will return a type of Continuation<T>.
<?hhfunction yieldInfiniteInts(): Continuation<int> {
$i = 0;
while (true) {
yield $i++;
}
}
$generator = yieldInfiniteInts();
foreach ($generator as $value) {
echo "$value\n";
}
Note: Do not use continuations in the context of asynchronous programming. Instead use asynchronous functions andAwaitable.
No comments:
Post a Comment