Files
kiri-core/kiri-engine/Pool/SplQueue.php
T

130 lines
1.7 KiB
PHP
Raw Normal View History

2022-02-24 15:24:29 +08:00
<?php
2023-04-16 01:45:34 +08:00
declare(strict_types=1);
2022-02-24 15:24:29 +08:00
namespace Kiri\Pool;
use JetBrains\PhpStorm\Pure;
/**
*
*/
class SplQueue implements QueueInterface
{
2023-04-03 13:54:09 +08:00
/**
* @var \SplQueue
*/
2022-02-24 15:24:29 +08:00
private \SplQueue $channel;
2023-04-03 13:54:09 +08:00
/**
* @var int
*/
2022-02-24 15:24:29 +08:00
public int $errCode = 0;
/**
* @param int $max
*/
#[Pure] public function __construct(public int $max)
{
$this->channel = new \SplQueue();
}
/**
* @return bool
*/
public function isEmpty(): bool
{
// TODO: Implement isEmpty() method.
return $this->channel->count() < 1;
}
/**
* @param mixed $data
* @param float $timeout
* @return bool
*/
public function push(mixed $data, float $timeout = -1): bool
{
// TODO: Implement push() method.
2022-07-11 18:53:19 +08:00
if ($this->isFull()) {
return false;
}
2022-02-24 15:24:29 +08:00
$this->channel->enqueue($data);
return true;
}
/**
* @param float $timeout
* @return mixed
*/
public function pop(float $timeout = -1): mixed
{
// TODO: Implement pop() method.
2022-06-17 14:30:31 +08:00
if ($this->channel->count() < 1) {
return null;
}
2022-02-24 15:24:29 +08:00
return $this->channel->dequeue();
}
/**
* @return array
*/
public function stats(): array
{
// TODO: Implement stats() method.
2022-09-19 18:45:22 +08:00
return [
'consumer_num' => 0,
'producer_num' => 0,
'queue_num' => $this->length()
];
2022-02-24 15:24:29 +08:00
}
/**
* @return bool
*/
public function close(): bool
{
// TODO: Implement close() method.
return false;
}
/**
* @return int
*/
public function length(): int
{
// TODO: Implement length() method.
return $this->channel->count();
}
/**
* @return bool
*/
public function isFull(): bool
{
// TODO: Implement isFull() method.
return $this->channel->count() >= $this->max;
}
2022-06-17 11:59:19 +08:00
/**
* @return bool
*/
public function isClose(): bool
{
return false;
}
2022-02-24 15:24:29 +08:00
}