@@ -6,7 +6,7 @@ import { ChannelListeners, PubSub, PubSubCommand, PubSubListener, PubSubType, Pu
6
6
import { AbortError , ErrorReply } from '../errors' ;
7
7
import { EventEmitter } from 'stream' ;
8
8
9
- export interface QueueCommandOptions {
9
+ export interface CommandOptions {
10
10
chainId ?: symbol ;
11
11
asap ?: boolean ;
12
12
abortSignal ?: AbortSignal ;
@@ -149,7 +149,7 @@ export default class RedisCommandsQueue {
149
149
} ) ;
150
150
}
151
151
152
- addCommand < T > ( args : CommandArguments , options ?: QueueCommandOptions ) : Promise < T > {
152
+ addCommand < T > ( args : CommandArguments , options ?: CommandOptions ) : Promise < T > {
153
153
if ( this . _maxLength && this . _waitingToBeSent . length + this . _waitingForReply . length >= this . _maxLength ) {
154
154
return Promise . reject ( new Error ( 'The queue is full' ) ) ;
155
155
} else if ( options ?. abortSignal ?. aborted ) {
@@ -256,30 +256,32 @@ export default class RedisCommandsQueue {
256
256
} ) ;
257
257
}
258
258
259
- getCommandToSend ( ) : CommandArguments | undefined {
260
- const toSend = this . _waitingToBeSent . shift ( ) ;
261
- if ( ! toSend ) return ;
262
-
263
- let encoded : CommandArguments ;
264
- try {
265
- encoded = encodeCommand ( toSend . args ) ;
266
- } catch ( err ) {
267
- toSend . reject ( err ) ;
268
- return ;
269
- }
259
+ * waitingToBeSent ( ) {
260
+ let toSend = this . _waitingToBeSent . shift ( ) ;
261
+ while ( toSend ) {
262
+ let encoded : CommandArguments ;
263
+ try {
264
+ encoded = encodeCommand ( toSend . args ) ;
265
+ } catch ( err ) {
266
+ toSend . reject ( err ) ;
267
+ toSend = this . _waitingToBeSent . shift ( ) ;
268
+ continue ;
269
+ }
270
270
271
- if ( toSend . abort ) {
272
- RedisCommandsQueue . _removeAbortListener ( toSend ) ;
273
- toSend . abort = undefined ;
271
+ if ( toSend . abort ) {
272
+ RedisCommandsQueue . _removeAbortListener ( toSend ) ;
273
+ toSend . abort = undefined ;
274
+ }
275
+
276
+ // TODO reuse `toSend` or create new object?
277
+ ( toSend as any ) . args = undefined ;
278
+ ( toSend as any ) . chainId = undefined ;
279
+
280
+ this . _waitingForReply . push ( toSend ) ;
281
+ this . _chainInExecution = toSend . chainId ;
282
+ yield encoded ;
283
+ toSend = this . _waitingToBeSent . shift ( ) ;
274
284
}
275
-
276
- // TODO reuse `toSend` or create new object?
277
- ( toSend as any ) . args = undefined ;
278
- ( toSend as any ) . chainId = undefined ;
279
-
280
- this . _waitingForReply . push ( toSend ) ;
281
- this . _chainInExecution = toSend . chainId ;
282
- return encoded ;
283
285
}
284
286
285
287
private _flushWaitingForReply ( err : Error ) : void {
0 commit comments