File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ let natsPackage = {} as any;
18
18
export class ClientNats extends ClientProxy {
19
19
protected readonly logger = new Logger ( ClientNats . name ) ;
20
20
protected natsClient : Client ;
21
+ protected clientConnectionPromise : Promise < Client > ;
21
22
22
23
constructor ( protected readonly options : NatsOptions [ 'options' ] ) {
23
24
super ( ) ;
@@ -30,13 +31,15 @@ export class ClientNats extends ClientProxy {
30
31
public async close ( ) {
31
32
await this . natsClient ?. close ( ) ;
32
33
this . natsClient = null ;
34
+ this . clientConnectionPromise = null ;
33
35
}
34
36
35
37
public async connect ( ) : Promise < any > {
36
- if ( this . natsClient ) {
37
- return this . natsClient ;
38
+ if ( this . clientConnectionPromise ) {
39
+ return this . clientConnectionPromise ;
38
40
}
39
- this . natsClient = await this . createClient ( ) ;
41
+ this . clientConnectionPromise = this . createClient ( ) ;
42
+ this . natsClient = await this . clientConnectionPromise ;
40
43
this . handleStatusUpdates ( this . natsClient ) ;
41
44
return this . natsClient ;
42
45
}
Original file line number Diff line number Diff line change @@ -253,6 +253,7 @@ describe('ClientNats', () => {
253
253
describe ( 'when is not connected' , ( ) => {
254
254
beforeEach ( async ( ) => {
255
255
client [ 'natsClient' ] = null ;
256
+ client [ 'clientConnectionPromise' ] = null ;
256
257
await client . connect ( ) ;
257
258
} ) ;
258
259
it ( 'should call "handleStatusUpdatesSpy" once' , async ( ) => {
You can’t perform that action at this time.
0 commit comments