This commit is contained in:
2021-03-29 14:02:16 +08:00
parent b7a785f7a1
commit f5c68e808b
+11 -5
View File
@@ -69,21 +69,27 @@ class Channel extends Component
/** /**
* @param $timeout
* @param Closure $closure * @param Closure $closure
* @param int $timeout
* @param string $name * @param string $name
* @param int $length
* @return mixed * @return mixed
* @throws Exception * @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.'); return $this->addError('Channel is full.');
} }
$data = null;
if (!$channel->isEmpty()) { 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;
} }