Skip to content

Commit

Permalink
🚧 integrate EventLoop->promiseAll
Browse files Browse the repository at this point in the history
  • Loading branch information
matyo91 committed Apr 21, 2021
1 parent 7bed8a1 commit b75a49c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Adapter/Swoole/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b75a49c

Please sign in to comment.