Close connection on __destruct
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user