From b19c9b22545fd0c6c8ae7ed765329b992af9db91 Mon Sep 17 00:00:00 2001 From: Mathieu Ledru Date: Wed, 21 Apr 2021 21:25:41 +0200 Subject: [PATCH] :construction: introduce Yield promise --- src/Adapter/Swoole/EventLoop.php | 1 - src/Adapter/Swoole/Internal/Promise.php | 26 ---------- src/Adapter/Swoole/Internal/YieldPromise.php | 51 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 27 deletions(-) delete mode 100644 src/Adapter/Swoole/Internal/Promise.php create mode 100644 src/Adapter/Swoole/Internal/YieldPromise.php diff --git a/src/Adapter/Swoole/EventLoop.php b/src/Adapter/Swoole/EventLoop.php index 64a9f6e..a68f200 100644 --- a/src/Adapter/Swoole/EventLoop.php +++ b/src/Adapter/Swoole/EventLoop.php @@ -72,7 +72,6 @@ public function promiseRace(Promise ...$promises): Promise */ public function promiseFulfilled($value): Promise { - new Pro } /** diff --git a/src/Adapter/Swoole/Internal/Promise.php b/src/Adapter/Swoole/Internal/Promise.php deleted file mode 100644 index 25fb4df..0000000 --- a/src/Adapter/Swoole/Internal/Promise.php +++ /dev/null @@ -1,26 +0,0 @@ -isSettled) { + return; + } + + $this->cids[Coroutine::getCid()] = true; + Coroutine::yield(); + } + + public function value() + { + assert($this->isSettled, new \Error('Promise is not resolved.')); + return $this->value; + } + + public function getPromise(): YieldPromise + { + return $this; + } + + public function resolve($value): void + { + assert(false === $this->isSettled, new \Error('Promise is already resolved.')); + $this->isSettled = true; + $this->value = $value; + foreach ($this->cids as $cid => $dummy) { + Coroutine::resume($cid); + } + $this->cids = []; + } + + public function reject(\Throwable $throwable): void + { + + } +}