This commit is contained in:
2021-04-22 14:53:14 +08:00
parent ed927e00e0
commit 1fb634df66
2 changed files with 5 additions and 10 deletions
+1 -1
View File
@@ -324,7 +324,7 @@ class ActiveRecord extends BaseActiveRecord
/** @var Channel $channel */ /** @var Channel $channel */
$channel = Snowflake::app()->get('channel'); $channel = Snowflake::app()->get('channel');
return $channel->push($this, get_called_class()); $channel->push($this, get_called_class());
} }
+4 -9
View File
@@ -8,7 +8,6 @@ use Closure;
use Exception; use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use SplQueue; use SplQueue;
use Swoole\Coroutine\Channel as CChannel;
/** /**
@@ -25,22 +24,18 @@ class Channel extends Component
/** /**
* @param mixed $value * @param mixed $value
* @param string $name * @param string $name
* @return mixed
* @throws Exception * @throws Exception
*/ */
public function push(mixed $value, string $name = ''): mixed public function push(mixed $value, string $name = ''): void
{ {
$channel = $this->channelInit($name); $channel = $this->channelInit($name);
if ($channel->isFull()) { $channel->enqueue($value);
return $this->addError('Channel is full.');
}
return $channel->push($value);
} }
/** /**
* @param string $name * @param string $name
* @return bool|CChannel * @return bool|SplQueue
*/ */
private function channelInit(string $name = ''): bool|SplQueue private function channelInit(string $name = ''): bool|SplQueue
{ {
@@ -82,7 +77,7 @@ class Channel extends Component
return $channel->pop(); return $channel->pop();
} }
if ($timeout !== null) { if ($timeout !== null) {
$data = $channel->pop($timeout); $data = $channel->dequeue();
} }
if (empty($data)) { if (empty($data)) {
$data = call_user_func($closure); $data = call_user_func($closure);