()
| 107 | } |
| 108 | |
| 109 | public connect(): Promise<any> { |
| 110 | if (this.client) { |
| 111 | return this.connectionPromise; |
| 112 | } |
| 113 | this.client = this.createClient(); |
| 114 | |
| 115 | this.registerErrorListener(this.client); |
| 116 | this.registerDisconnectListener(this.client); |
| 117 | this.registerConnectListener(this.client); |
| 118 | this.registerBlockedListener(this.client); |
| 119 | this.registerUnblockedListener(this.client); |
| 120 | this.pendingEventListeners.forEach(({ event, callback }) => |
| 121 | this.client!.on(event, callback), |
| 122 | ); |
| 123 | this.pendingEventListeners = []; |
| 124 | |
| 125 | this.responseEmitter = new EventEmitter(); |
| 126 | this.responseEmitter.setMaxListeners(0); |
| 127 | |
| 128 | const connect$ = this.connect$(this.client); |
| 129 | const withDisconnect$ = this.mergeDisconnectEvent( |
| 130 | this.client, |
| 131 | connect$, |
| 132 | ).pipe(switchMap(() => this.createChannel())); |
| 133 | |
| 134 | const withReconnect$ = fromEvent(this.client, RmqEventsMap.CONNECT).pipe( |
| 135 | skip(1), |
| 136 | ); |
| 137 | const source$ = merge(withDisconnect$, withReconnect$); |
| 138 | |
| 139 | this.connection$ = new ReplaySubject(1); |
| 140 | source$.subscribe(this.connection$); |
| 141 | this.connectionPromise = this.convertConnectionToPromise(); |
| 142 | |
| 143 | return this.connectionPromise; |
| 144 | } |
| 145 | |
| 146 | public createChannel(): Promise<void> { |
| 147 | return new Promise(resolve => { |
no test coverage detected