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

@ -9,6 +9,7 @@ use Amp\Promise;
use Nsq\Config\ClientConfig;
use Nsq\Exception\ConsumerException;
use Nsq\Frame\Response;
use Nsq\Stream\NullStream;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use function Amp\asyncCall;
@ -60,6 +61,11 @@ final class Consumer extends Connection implements ConsumerInterface
public function connect(): Promise
{
if (!$this->stream instanceof NullStream) {
return call(static function (): void {
});
}
return call(function (): \Generator {
yield parent::connect();
@ -113,6 +119,8 @@ final class Consumer extends Connection implements ConsumerInterface
}
}
}
$this->stream = new NullStream();
});
});
}