Skip to content

Commit

Permalink
Improve the logic of close
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Dec 6, 2019
1 parent 8ca48a7 commit 9644893
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Swoole;

use RuntimeException;
use Swoole\Coroutine\Channel;
use Throwable;

Expand Down Expand Up @@ -55,6 +56,9 @@ public function fill(): void

public function get()
{
if ($this->pool === null) {
throw new RuntimeException('Pool has been closed');
}
if ($this->pool->isEmpty() && $this->num < $this->size) {
$this->make();
}
Expand All @@ -63,6 +67,9 @@ public function get()

public function put($connection): void
{
if ($this->pool === null) {
return;
}
if ($connection !== null) {
$this->pool->push($connection);
} else {
Expand All @@ -75,5 +82,6 @@ public function close(): void
{
$this->pool->close();
$this->pool = null;
$this->num = 0;
}
}

0 comments on commit 9644893

Please sign in to comment.