From 156ae14e7cc0f7b2938a1088028f5315ccbe78ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 14 Sep 2020 10:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Pagination.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Database/Pagination.php b/Database/Pagination.php index e6fccb41..8a531254 100644 --- a/Database/Pagination.php +++ b/Database/Pagination.php @@ -7,6 +7,8 @@ namespace Database; use Snowflake\Abstracts\Component; use Closure; use Exception; +use Snowflake\Snowflake; +use Swoole\Coroutine; /** * Class Pagination @@ -111,11 +113,9 @@ class Pagination extends Component return; } [$length, $data] = $this->get(); - if ($param !== null) { - call_user_func($this->_callback, $data, $param); - } else { - call_user_func($this->_callback, $data); - } + + $this->runner($data, $param); + unset($data); if ($length < $this->_limit) { return; @@ -124,6 +124,28 @@ class Pagination extends Component } + /** + * @param $data + * @param $param + */ + private function runner($data, $param) + { + if (Snowflake::inCoroutine()) { + if ($param !== null) { + Coroutine::create($this->_callback, $data, $param); + } else { + Coroutine::create($this->_callback, $data, $param); + } + } else { + if ($param !== null) { + call_user_func($this->_callback, $data, $param); + } else { + call_user_func($this->_callback, $data); + } + } + } + + /** * @return array|Collection */