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
+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);