-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Dynamic promise stack #46
Comments
up ? |
Hi everyone, For people who ran into the same issue, here's a simple function to fix it: use GuzzleHttp\Promise\PromiseInterface;
class PromiseStack {
/**
* @param PromiseInterface[]|array|\Traversable|\Generator $promises
* @return PromiseInterface
*/
public static function all($promises) : PromiseInterface {
return \GuzzleHttp\Promise\all($promises)->then(function ($result) use (&$promises) {
foreach ($promises AS $promise) {
if (\GuzzleHttp\Promise\PromiseInterface::PENDING === $promise->getState()) {
return static::all($promises);
}
}
return $result;
});
}
} I just don't understand why this is not the default behavior of Guzzle's |
bpolaszek
added a commit
to bpolaszek/promises
that referenced
this issue
Dec 22, 2016
mtdowling
added a commit
that referenced
this issue
May 20, 2017
bpolaszek
added a commit
to bpolaszek/promises
that referenced
this issue
Oct 26, 2017
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hello,
TL; DR
Guzzle's
all($promises)
function should be recursive: resolution of$promises
may add new promises into the$promises
stack. These new promises should not be left pending.Example
I'm using Guzzle's
all()
function to resolve a collection of promises, stored in an iterator.What if one of these promises, when resolved, adds a new promise to the stack?
Have a look at the following code:
I expect the following output:
But I get this:
And my
$secondPromise
state ispending
. Why is it not resolved?Thank you,
Ben
The text was updated successfully, but these errors were encountered: