diff --git a/.travis.yml b/.travis.yml index 17cf639..1c5e904 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ before_script: - phpenv config-rm xdebug.ini - composer install +before_install: + - printf "\n" | pecl install swoole + env: - TASK=tests-unit - TASK=tests-examples 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); });