From 1d33364698edf106a5fb902e65c9ee0b964c6d03 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 10 Jul 2018 18:33:00 -0500 Subject: [PATCH] Remove setIdleTimeout() Moved to constructor argument. --- src/AbstractPool.php | 23 +++++++++++++---------- src/Pool.php | 5 ----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/AbstractPool.php b/src/AbstractPool.php index fde0bd9..2d1e74c 100644 --- a/src/AbstractPool.php +++ b/src/AbstractPool.php @@ -41,7 +41,7 @@ abstract class AbstractPool implements Pool private $pending = 0; /** @var int */ - private $idleTimeout = Pool::DEFAULT_IDLE_TIMEOUT; + private $idleTimeout; /** @var string */ private $timeoutWatcher; @@ -98,15 +98,27 @@ abstract class AbstractPool implements Pool */ abstract protected function createTransaction(Transaction $transaction, callable $release): Transaction; + /** + * @param ConnectionConfig $config + * @param int $maxConnections Maximum number of active connections in the pool. + * @param int $idleTimeout Number of seconds until idle connections are removed from the pool. + * @param Connector|null $connector + */ public function __construct( ConnectionConfig $config, int $maxConnections = Pool::DEFAULT_MAX_CONNECTIONS, + int $idleTimeout = Pool::DEFAULT_IDLE_TIMEOUT, Connector $connector = null ) { $this->connector = $connector ?? $this->createDefaultConnector(); $this->connectionConfig = $config; + $this->idleTimeout = $idleTimeout; + if ($this->idleTimeout < 1) { + throw new \Error("The idle timeout must be 1 or greater"); + } + $this->maxConnections = $maxConnections; if ($this->maxConnections < 1) { throw new \Error("Pool must contain at least one connection"); @@ -148,15 +160,6 @@ abstract class AbstractPool implements Pool return $this->idleTimeout; } - public function setIdleTimeout(int $timeout) - { - if ($timeout < 1) { - throw new \Error("Timeout must be greater than or equal to 1"); - } - - $this->idleTimeout = $timeout; - } - public function lastUsedAt(): int { // Simple implementation... can be improved if needed. diff --git a/src/Pool.php b/src/Pool.php index 1c71b96..2903042 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -33,9 +33,4 @@ interface Pool extends Link * @return int Number of seconds a connection may remain idle before it is automatically closed. */ public function getIdleTimeout(): int; - - /** - * @param int $timeout Number of seconds a connection may remain idle before it is automatically closed. - */ - public function setIdleTimeout(int $timeout); }