Close connection on __destruct

This commit is contained in:
2021-02-04 23:07:41 +03:00
parent 15296f4b61
commit b126094e74

View File

@@ -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<void>
*/
@@ -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 {