Make connect methods idempotent

This commit is contained in:
2021-02-28 20:26:08 +03:00
parent e670cb161c
commit 9f004417fa
3 changed files with 24 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ namespace Nsq;
use Amp\Promise;
use Nsq\Config\ClientConfig;
use Nsq\Exception\NsqException;
use Nsq\Stream\NullStream;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use function Amp\asyncCall;
@@ -28,6 +29,11 @@ final class Producer extends Connection
public function connect(): Promise
{
if (!$this->stream instanceof NullStream) {
return call(static function (): void {
});
}
return call(function (): \Generator {
yield parent::connect();
@@ -83,6 +89,8 @@ final class Producer extends Connection
}
}
}
$this->stream = new NullStream();
});
}
}