@@ -58,9 +58,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
58
58
/** Is the client still processing a call? */
59
59
protected _processing : boolean = false ;
60
60
61
- /** Processing interval */
62
- protected _processingInterval ?: number ;
63
-
64
61
/**
65
62
* Initializes this client instance.
66
63
*
@@ -166,14 +163,12 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
166
163
* @inheritDoc
167
164
*/
168
165
public flush ( timeout ?: number ) : Promise < boolean > {
169
- return this . _isClientProcessing ( timeout ) . then ( clientReady => {
170
- if ( this . _processingInterval ) {
171
- clearInterval ( this . _processingInterval ) ;
172
- }
166
+ return this . _isClientProcessing ( timeout ) . then ( status => {
167
+ clearInterval ( status . interval ) ;
173
168
return this . _getBackend ( )
174
169
. getTransport ( )
175
170
. close ( timeout )
176
- . then ( transportFlushed => clientReady && transportFlushed ) ;
171
+ . then ( transportFlushed => status . ready && transportFlushed ) ;
177
172
} ) ;
178
173
}
179
174
@@ -207,20 +202,27 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
207
202
}
208
203
209
204
/** Waits for the client to be done with processing. */
210
- protected _isClientProcessing ( timeout ?: number ) : Promise < boolean > {
211
- return new Promise < boolean > ( resolve => {
205
+ protected _isClientProcessing ( timeout ?: number ) : Promise < { ready : boolean ; interval : number } > {
206
+ return new Promise < { ready : boolean ; interval : number } > ( resolve => {
212
207
let ticked : number = 0 ;
213
208
const tick : number = 1 ;
214
- if ( this . _processingInterval ) {
215
- clearInterval ( this . _processingInterval ) ;
216
- }
217
- this . _processingInterval = ( setInterval ( ( ) => {
209
+
210
+ let interval = 0 ;
211
+ clearInterval ( interval ) ;
212
+
213
+ interval = ( setInterval ( ( ) => {
218
214
if ( ! this . _processing ) {
219
- resolve ( true ) ;
215
+ resolve ( {
216
+ interval,
217
+ ready : true ,
218
+ } ) ;
220
219
} else {
221
220
ticked += tick ;
222
221
if ( timeout && ticked >= timeout ) {
223
- resolve ( false ) ;
222
+ resolve ( {
223
+ interval,
224
+ ready : false ,
225
+ } ) ;
224
226
}
225
227
}
226
228
} , tick ) as unknown ) as number ;
0 commit comments