From b75a49c204b3d4dadb3131cd8bde0c20b1613cde Mon Sep 17 00:00:00 2001 From: Mathieu Ledru Date: Thu, 22 Apr 2021 00:05:29 +0200 Subject: [PATCH] :construction: integrate EventLoop->promiseAll --- src/Adapter/Swoole/EventLoop.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Adapter/Swoole/EventLoop.php b/src/Adapter/Swoole/EventLoop.php index fab6fed..402a5b9 100644 --- a/src/Adapter/Swoole/EventLoop.php +++ b/src/Adapter/Swoole/EventLoop.php @@ -7,7 +7,6 @@ use M6Web\Tornado\Deferred; use M6Web\Tornado\Promise; use Swoole\Coroutine; -use Swoole\Coroutine\WaitGroup; use Swoole\Event; use RuntimeException; use function extension_loaded; @@ -64,8 +63,17 @@ public function promiseAll(Promise ...$promises): Promise { $promise = new YieldPromise(); + $ticks = count($promises); + $result = []; + $key = 0; foreach ($promises as $p) { - + $result[$key] = $this->wait($p); + $ticks--; + if($ticks === 0) { + ksort($result); + $promise->resolve($result); + } + $key++; } return $promise;