改名
This commit is contained in:
+34
-5
@@ -21,6 +21,36 @@ class Channel extends Component
|
||||
private static array $_channels = [];
|
||||
|
||||
|
||||
private static array $_waitRecover = [];
|
||||
|
||||
|
||||
public function init()
|
||||
{
|
||||
Event::on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'recover']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回收对象
|
||||
*/
|
||||
public function recover()
|
||||
{
|
||||
foreach (Channel::$_waitRecover as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
$channel = $this->channelInit($key);
|
||||
if ($channel->count() >= 100) {
|
||||
continue;
|
||||
}
|
||||
foreach ($value as $item) {
|
||||
$channel->enqueue($item);
|
||||
}
|
||||
}
|
||||
Channel::$_waitRecover = [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param string $name
|
||||
@@ -28,11 +58,10 @@ class Channel extends Component
|
||||
*/
|
||||
public function push(mixed $value, string $name = ''): void
|
||||
{
|
||||
$channel = $this->channelInit($name);
|
||||
if ($channel->count() >= 100) {
|
||||
return;
|
||||
if (!isset(Channel::$_waitRecover[$name])) {
|
||||
Channel::$_waitRecover[$name] = [];
|
||||
}
|
||||
$channel->enqueue($value);
|
||||
Channel::$_waitRecover[$name][] = $value;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +108,7 @@ class Channel extends Component
|
||||
if ($channel->isEmpty()) {
|
||||
return call_user_func($closure);
|
||||
}
|
||||
return clone $channel->dequeue();
|
||||
return $channel->dequeue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user