Check promise all equal
This commit is contained in:
parent
831429f00c
commit
10449822ce
1 changed files with 3 additions and 6 deletions
|
@ -6,8 +6,6 @@ use GraphQL\Error\InvariantViolation;
|
||||||
use GraphQL\Executor\Promise\Promise;
|
use GraphQL\Executor\Promise\Promise;
|
||||||
use GraphQL\Executor\Promise\PromiseAdapter;
|
use GraphQL\Executor\Promise\PromiseAdapter;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
use function Co\go;
|
|
||||||
use function Co\run;
|
|
||||||
|
|
||||||
class SwoolePromiseAdapter implements PromiseAdapter
|
class SwoolePromiseAdapter implements PromiseAdapter
|
||||||
{
|
{
|
||||||
|
@ -68,7 +66,7 @@ class SwoolePromiseAdapter implements PromiseAdapter
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
run(function ($promisesOrValues, $all, $total, &$count, $result) {
|
\Co\run(function ($promisesOrValues, $all, $total, &$count, $result) {
|
||||||
foreach ($promisesOrValues as $index => $promiseOrValue) {
|
foreach ($promisesOrValues as $index => $promiseOrValue) {
|
||||||
go(function ($index, $promiseOrValue, $all, $total, &$count, $result) {
|
go(function ($index, $promiseOrValue, $all, $total, &$count, $result) {
|
||||||
if (!($promiseOrValue instanceof SwoolePromise)) {
|
if (!($promiseOrValue instanceof SwoolePromise)) {
|
||||||
|
@ -81,10 +79,9 @@ class SwoolePromiseAdapter implements PromiseAdapter
|
||||||
static function ($value) use ($index, &$count, $total, &$result, $all): void {
|
static function ($value) use ($index, &$count, $total, &$result, $all): void {
|
||||||
$result[$index] = $value;
|
$result[$index] = $value;
|
||||||
$count++;
|
$count++;
|
||||||
if ($count < $total) {
|
if ($count === $total) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
$all->resolve($result);
|
$all->resolve($result);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[$all, 'reject']
|
[$all, 'reject']
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue