diff --git a/src/Connection.php b/src/Connection.php index 94c860c..ca88d71 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -11,6 +11,7 @@ use Amp\ByteStream\ZlibOutputStream; use Amp\Failure; use Amp\Promise; use Amp\Socket\Socket; +use Amp\Success; use Nsq\Config\ClientConfig; use Nsq\Config\ConnectionConfig; use Nsq\Exception\AuthenticationRequired; @@ -62,6 +63,11 @@ abstract class Connection $this->logger = $logger ?? new NullLogger(); } + public function __destruct() + { + $this->close(); + } + /** * @return Promise */ @@ -123,7 +129,7 @@ abstract class Connection public function close(): Promise { if (null === $this->socket) { - return new Failure(new NotConnected()); + return new Success(); } return call(function (): \Generator {