This commit is contained in:
2021-03-29 13:58:15 +08:00
parent b955b69caa
commit b7a785f7a1
+5 -3
View File
@@ -4,6 +4,7 @@
namespace Snowflake; namespace Snowflake;
use Closure;
use Exception; use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Swoole\Coroutine\Channel as CChannel; use Swoole\Coroutine\Channel as CChannel;
@@ -68,20 +69,21 @@ class Channel extends Component
/** /**
* @param Closure $closure
* @param int $timeout * @param int $timeout
* @param string $name * @param string $name
* @return mixed * @return mixed
* @throws Exception * @throws Exception
*/ */
public function pop($timeout = 1, string $name = ''): mixed public function pop(Closure $closure, $timeout = 1, string $name = ''): mixed
{ {
if ($channel = $this->channelInit(0, $name)) { if (($channel = $this->channelInit(0, $name)) == false) {
return $this->addError('Channel is full.'); return $this->addError('Channel is full.');
} }
if (!$channel->isEmpty()) { if (!$channel->isEmpty()) {
return $channel->pop($timeout); return $channel->pop($timeout);
} }
return null; return call_user_func($closure);
} }