How does awaiting all promises work with promises that contain generators
CMCDragonkai opened this issue · 4 comments
I am intending to use https://github.com/clue/php-buzz-react to asynchronously query a list of remote sites, where each query may optionally require chaining a recursive query into it to perform pagination of the remote site's results.
My blocking system is doing this via a do while
loop and generator yield
. As I consume each yield, it may in turn perform the next paginated query.
Now that I want to do this asynchronously, I'm concerned as to how a promise yielding a generator of results behave in this case?
$promises = [
$browser->get('http://example.com/')->then(function ($response) {
foreach ($response->getParsedBody()['rows'] as $row) {
yield $row;
}
})
];
$allResults = Block\awaitAll($promises, $loop);
Another idea is this, can awaitAll
await on a generator of promises? Right now the type is specified as array
, why not Traversable
?
For reference: https://github.com/nikic/iter
It appears to work!
Thanks for the confirmation that the above works as expected