From d1ad39cf87e852b407809dd97a4ed2f883fb1bb4 Mon Sep 17 00:00:00 2001 From: Mathieu Ledru Date: Sat, 24 Apr 2021 17:36:52 +0200 Subject: [PATCH] :construction_worker: travis CI --- src/Adapter/Swoole/EventLoop.php | 1 - src/Adapter/Swoole/Internal/DummyPromise.php | 16 ++++------------ src/Adapter/Swoole/YieldEventLoop.php | 7 ++++--- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/Adapter/Swoole/EventLoop.php b/src/Adapter/Swoole/EventLoop.php index adbc9b1..0211e4c 100644 --- a/src/Adapter/Swoole/EventLoop.php +++ b/src/Adapter/Swoole/EventLoop.php @@ -77,7 +77,6 @@ private function pushCoroutine(): void $cid = Coroutine::getCid(); $this->cids[] = $cid; Coroutine::yield(); - } private function createPromise(): DummyPromise diff --git a/src/Adapter/Swoole/Internal/DummyPromise.php b/src/Adapter/Swoole/Internal/DummyPromise.php index 5d3be27..c6735ad 100644 --- a/src/Adapter/Swoole/Internal/DummyPromise.php +++ b/src/Adapter/Swoole/Internal/DummyPromise.php @@ -8,24 +8,16 @@ final class DummyPromise implements Promise, Deferred { - /** - * @var bool - */ + /** @var bool */ private $isPending; - /** - * @var mixed - */ + /** @var mixed */ private $value; - /** - * @var Throwable|null - */ + /** @var Throwable|null */ private $exception; - /** - * @var callable[] - */ + /** @var callable[] */ private $callbacks; public function __construct(?callable $callback = null) diff --git a/src/Adapter/Swoole/YieldEventLoop.php b/src/Adapter/Swoole/YieldEventLoop.php index 8b54c34..b40ba49 100644 --- a/src/Adapter/Swoole/YieldEventLoop.php +++ b/src/Adapter/Swoole/YieldEventLoop.php @@ -66,11 +66,12 @@ public function async(\Generator $generator): Promise Coroutine::create(function () use ($generator, $deferred, $fnWrapGenerator) { if (!$generator->valid()) { $deferred->resolve($generator->getReturn()); + return; } $promise = DummyPromise::wrap($generator->current()); - if($this->isPending($promise)) { + if ($this->isPending($promise)) { $cid = Coroutine::getCid(); $promise->addCallback(function () use ($cid) { Coroutine::resume($cid); @@ -96,7 +97,7 @@ public function promiseAll(Promise ...$promises): Promise $wg = new Coroutine\WaitGroup(); $result = []; foreach ($promises as $index => $promise) { - $this->async((static function() use($wg, &$result, $index, $promise){ + $this->async((static function () use ($wg, &$result, $index, $promise) { $wg->add(); $result[$index] = yield $promise; $wg->done(); @@ -104,7 +105,7 @@ public function promiseAll(Promise ...$promises): Promise } $deferred = $this->deferred(); - Coroutine::create(function() use($wg, $deferred, &$result) { + Coroutine::create(function () use ($wg, $deferred, &$result) { $wg->wait(); $deferred->resolve($result); });