This commit is contained in:
2023-08-16 16:33:57 +08:00
parent c8f7a7dcb2
commit 04db55e79a
3 changed files with 142 additions and 114 deletions
+11
View File
@@ -82,6 +82,17 @@ class Pool implements PoolInterface
}
/**
* @param string $name
* @return void
* @throws Exception
*/
public function abandon(string $name): void
{
$this->channel($name)->abandon();
}
/**
* @param string $name
* @return array
+7
View File
@@ -22,6 +22,13 @@ interface PoolInterface
public function get(string $name): mixed;
/**
* @param string $name
* @return void
*/
public function abandon(string $name): void;
/**
* @param string $name
* @param mixed $data
+12 -2
View File
@@ -76,7 +76,7 @@ class PoolItem
public function push(mixed $item): void
{
if (is_null($item)) {
$item = call_user_func($this->callback);
return;
}
$this->_items->push($item);
}
@@ -126,13 +126,23 @@ class PoolItem
}
/**
* @return void
*/
public function abandon(): void
{
$this->created -= 1;
}
/**
* @param int $waite
* @return mixed
*/
public function pop(int $waite = 10): mixed
{
if ($this->_items->isEmpty()) {
if ($this->_items->isEmpty() && $this->created >= $this->maxCreated) {
$this->created += 1;
return call_user_func($this->callback);
} else {
return $this->_items->pop($waite);