Make connect methods idempotent
This commit is contained in:
@@ -9,6 +9,7 @@ use Amp\Promise;
|
|||||||
use Nsq\Config\ClientConfig;
|
use Nsq\Config\ClientConfig;
|
||||||
use Nsq\Exception\ConsumerException;
|
use Nsq\Exception\ConsumerException;
|
||||||
use Nsq\Frame\Response;
|
use Nsq\Frame\Response;
|
||||||
|
use Nsq\Stream\NullStream;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
use function Amp\asyncCall;
|
use function Amp\asyncCall;
|
||||||
@@ -60,6 +61,11 @@ final class Consumer extends Connection implements ConsumerInterface
|
|||||||
|
|
||||||
public function connect(): Promise
|
public function connect(): Promise
|
||||||
{
|
{
|
||||||
|
if (!$this->stream instanceof NullStream) {
|
||||||
|
return call(static function (): void {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return call(function (): \Generator {
|
return call(function (): \Generator {
|
||||||
yield parent::connect();
|
yield parent::connect();
|
||||||
|
|
||||||
@@ -113,6 +119,8 @@ final class Consumer extends Connection implements ConsumerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->stream = new NullStream();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ namespace Nsq;
|
|||||||
use Amp\Promise;
|
use Amp\Promise;
|
||||||
use Nsq\Config\ClientConfig;
|
use Nsq\Config\ClientConfig;
|
||||||
use Nsq\Exception\NsqException;
|
use Nsq\Exception\NsqException;
|
||||||
|
use Nsq\Stream\NullStream;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
use function Amp\asyncCall;
|
use function Amp\asyncCall;
|
||||||
@@ -28,6 +29,11 @@ final class Producer extends Connection
|
|||||||
|
|
||||||
public function connect(): Promise
|
public function connect(): Promise
|
||||||
{
|
{
|
||||||
|
if (!$this->stream instanceof NullStream) {
|
||||||
|
return call(static function (): void {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return call(function (): \Generator {
|
return call(function (): \Generator {
|
||||||
yield parent::connect();
|
yield parent::connect();
|
||||||
|
|
||||||
@@ -83,6 +89,8 @@ final class Producer extends Connection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->stream = new NullStream();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ use Amp\Success;
|
|||||||
use Nsq\Config\ClientConfig;
|
use Nsq\Config\ClientConfig;
|
||||||
use Nsq\Exception\ConsumerException;
|
use Nsq\Exception\ConsumerException;
|
||||||
use Nsq\Frame\Response;
|
use Nsq\Frame\Response;
|
||||||
|
use Nsq\Stream\NullStream;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
use function Amp\asyncCall;
|
use function Amp\asyncCall;
|
||||||
@@ -64,6 +65,11 @@ final class Reader extends Connection implements ConsumerInterface
|
|||||||
*/
|
*/
|
||||||
public function connect(): Promise
|
public function connect(): Promise
|
||||||
{
|
{
|
||||||
|
if (!$this->stream instanceof NullStream) {
|
||||||
|
return call(static function (): void {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return call(function (): \Generator {
|
return call(function (): \Generator {
|
||||||
yield parent::connect();
|
yield parent::connect();
|
||||||
|
|
||||||
@@ -131,6 +137,8 @@ final class Reader extends Connection implements ConsumerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->stream = new NullStream();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user