From f5c68e808bf5ba2555973da7c8a5b5f9af4277e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 29 Mar 2021 14:02:16 +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 --- System/Channel.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/System/Channel.php b/System/Channel.php index 331c7613..78883bd7 100644 --- a/System/Channel.php +++ b/System/Channel.php @@ -69,21 +69,27 @@ class Channel extends Component /** + * @param $timeout * @param Closure $closure - * @param int $timeout * @param string $name + * @param int $length * @return mixed * @throws Exception */ - public function pop(Closure $closure, $timeout = 1, string $name = ''): mixed + public function pop(int|float $timeout, Closure $closure, string $name = '', int $length = 9999): mixed { - if (($channel = $this->channelInit(0, $name)) == false) { + if (($channel = $this->channelInit($length, $name)) == false) { return $this->addError('Channel is full.'); } + + $data = null; if (!$channel->isEmpty()) { - return $channel->pop($timeout); + $data = $channel->pop($timeout); } - return call_user_func($closure); + if (empty($data)) { + $data = call_user_func($closure); + } + return $data; }