@@ -19,7 +19,6 @@ import {
19
19
20
20
import { ConsumerOptions , StopOptions , UpdatableOptions } from "./types.js" ;
21
21
import { TypedEventEmitter } from "./emitter.js" ;
22
- import { autoBind } from "./bind.js" ;
23
22
import {
24
23
SQSError ,
25
24
TimeoutError ,
@@ -89,7 +88,6 @@ export class Consumer extends TypedEventEmitter {
89
88
useQueueUrlAsEndpoint : options . useQueueUrlAsEndpoint ?? true ,
90
89
region : options . region || process . env . AWS_REGION || "eu-west-1" ,
91
90
} ) ;
92
- autoBind ( this ) ;
93
91
}
94
92
95
93
/**
@@ -161,7 +159,7 @@ export class Consumer extends TypedEventEmitter {
161
159
return ;
162
160
}
163
161
164
- const exceededTimeout =
162
+ const exceededTimeout : boolean =
165
163
Date . now ( ) - this . stopRequestedAtTimestamp >
166
164
this . pollingCompleteWaitTimeMs ;
167
165
if ( exceededTimeout ) {
@@ -171,7 +169,7 @@ export class Consumer extends TypedEventEmitter {
171
169
}
172
170
173
171
this . emit ( "waiting_for_polling_to_complete" ) ;
174
- setTimeout ( this . waitForPollingToComplete , 1000 ) ;
172
+ setTimeout ( ( ) => this . waitForPollingToComplete ( ) , 1000 ) ;
175
173
}
176
174
177
175
/**
@@ -196,7 +194,7 @@ export class Consumer extends TypedEventEmitter {
196
194
public updateOption (
197
195
option : UpdatableOptions ,
198
196
value : ConsumerOptions [ UpdatableOptions ] ,
199
- ) {
197
+ ) : void {
200
198
validateOption ( option , value , this , true ) ;
201
199
202
200
this [ option ] = value ;
@@ -237,7 +235,7 @@ export class Consumer extends TypedEventEmitter {
237
235
238
236
this . isPolling = true ;
239
237
240
- let currentPollingTimeout = this . pollingWaitTimeMs ;
238
+ let currentPollingTimeout : number = this . pollingWaitTimeMs ;
241
239
this . receiveMessage ( {
242
240
QueueUrl : this . queueUrl ,
243
241
AttributeNames : this . attributeNames ,
@@ -246,8 +244,10 @@ export class Consumer extends TypedEventEmitter {
246
244
WaitTimeSeconds : this . waitTimeSeconds ,
247
245
VisibilityTimeout : this . visibilityTimeout ,
248
246
} )
249
- . then ( this . handleSqsResponse )
250
- . catch ( ( err ) => {
247
+ . then ( ( output : ReceiveMessageCommandOutput ) =>
248
+ this . handleSqsResponse ( output ) ,
249
+ )
250
+ . catch ( ( err ) : void => {
251
251
this . emitError ( err ) ;
252
252
if ( isConnectionError ( err ) ) {
253
253
logger . debug ( "authentication_error" , {
@@ -258,16 +258,19 @@ export class Consumer extends TypedEventEmitter {
258
258
}
259
259
return ;
260
260
} )
261
- . then ( ( ) => {
261
+ . then ( ( ) : void => {
262
262
if ( this . pollingTimeoutId ) {
263
263
clearTimeout ( this . pollingTimeoutId ) ;
264
264
}
265
- this . pollingTimeoutId = setTimeout ( this . poll , currentPollingTimeout ) ;
265
+ this . pollingTimeoutId = setTimeout (
266
+ ( ) => this . poll ( ) ,
267
+ currentPollingTimeout ,
268
+ ) ;
266
269
} )
267
- . catch ( ( err ) => {
270
+ . catch ( ( err ) : void => {
268
271
this . emitError ( err ) ;
269
272
} )
270
- . finally ( ( ) => {
273
+ . finally ( ( ) : void => {
271
274
this . isPolling = false ;
272
275
} ) ;
273
276
}
@@ -283,7 +286,7 @@ export class Consumer extends TypedEventEmitter {
283
286
if ( this . preReceiveMessageCallback ) {
284
287
await this . preReceiveMessageCallback ( ) ;
285
288
}
286
- const result = await this . sqs . send (
289
+ const result : ReceiveMessageCommandOutput = await this . sqs . send (
287
290
new ReceiveMessageCommand ( params ) ,
288
291
this . sqsSendOptions ,
289
292
) ;
@@ -309,7 +312,11 @@ export class Consumer extends TypedEventEmitter {
309
312
if ( this . handleMessageBatch ) {
310
313
await this . processMessageBatch ( response . Messages ) ;
311
314
} else {
312
- await Promise . all ( response . Messages . map ( this . processMessage ) ) ;
315
+ await Promise . all (
316
+ response . Messages . map ( ( message : Message ) =>
317
+ this . processMessage ( message ) ,
318
+ ) ,
319
+ ) ;
313
320
}
314
321
315
322
this . emit ( "response_processed" ) ;
@@ -333,7 +340,7 @@ export class Consumer extends TypedEventEmitter {
333
340
heartbeatTimeoutId = this . startHeartbeat ( message ) ;
334
341
}
335
342
336
- const ackedMessage = await this . executeHandler ( message ) ;
343
+ const ackedMessage : Message = await this . executeHandler ( message ) ;
337
344
338
345
if ( ackedMessage ?. MessageId === message . MessageId ) {
339
346
await this . deleteMessage ( message ) ;
@@ -361,20 +368,20 @@ export class Consumer extends TypedEventEmitter {
361
368
let heartbeatTimeoutId : NodeJS . Timeout | undefined = undefined ;
362
369
363
370
try {
364
- messages . forEach ( ( message ) => {
371
+ messages . forEach ( ( message : Message ) : void => {
365
372
this . emit ( "message_received" , message ) ;
366
373
} ) ;
367
374
368
375
if ( this . heartbeatInterval ) {
369
376
heartbeatTimeoutId = this . startHeartbeat ( null , messages ) ;
370
377
}
371
378
372
- const ackedMessages = await this . executeBatchHandler ( messages ) ;
379
+ const ackedMessages : Message [ ] = await this . executeBatchHandler ( messages ) ;
373
380
374
381
if ( ackedMessages ?. length > 0 ) {
375
382
await this . deleteMessageBatch ( ackedMessages ) ;
376
383
377
- ackedMessages . forEach ( ( message ) => {
384
+ ackedMessages . forEach ( ( message : Message ) : void => {
378
385
this . emit ( "message_processed" , message ) ;
379
386
} ) ;
380
387
}
@@ -448,7 +455,7 @@ export class Consumer extends TypedEventEmitter {
448
455
) : Promise < ChangeMessageVisibilityBatchCommandOutput > {
449
456
const params : ChangeMessageVisibilityBatchCommandInput = {
450
457
QueueUrl : this . queueUrl ,
451
- Entries : messages . map ( ( message ) => ( {
458
+ Entries : messages . map ( ( message : Message ) => ( {
452
459
Id : message . MessageId ,
453
460
ReceiptHandle : message . ReceiptHandle ,
454
461
VisibilityTimeout : timeout ,
@@ -479,7 +486,7 @@ export class Consumer extends TypedEventEmitter {
479
486
let result ;
480
487
481
488
if ( this . handleMessageTimeout ) {
482
- const pending = new Promise ( ( _ , reject ) => {
489
+ const pending : Promise < void > = new Promise ( ( _ , reject ) : void => {
483
490
handleMessageTimeoutId = setTimeout ( ( ) : void => {
484
491
reject ( new TimeoutError ( ) ) ;
485
492
} , this . handleMessageTimeout ) ;
@@ -518,7 +525,7 @@ export class Consumer extends TypedEventEmitter {
518
525
*/
519
526
private async executeBatchHandler ( messages : Message [ ] ) : Promise < Message [ ] > {
520
527
try {
521
- const result = await this . handleMessageBatch ( messages ) ;
528
+ const result : void | Message [ ] = await this . handleMessageBatch ( messages ) ;
522
529
523
530
return ! this . alwaysAcknowledge && result instanceof Object
524
531
? result
@@ -576,12 +583,12 @@ export class Consumer extends TypedEventEmitter {
576
583
return ;
577
584
}
578
585
logger . debug ( "deleting_messages" , {
579
- messageIds : messages . map ( ( msg ) => msg . MessageId ) ,
586
+ messageIds : messages . map ( ( msg : Message ) => msg . MessageId ) ,
580
587
} ) ;
581
588
582
589
const deleteParams : DeleteMessageBatchCommandInput = {
583
590
QueueUrl : this . queueUrl ,
584
- Entries : messages . map ( ( message ) => ( {
591
+ Entries : messages . map ( ( message : Message ) => ( {
585
592
Id : message . MessageId ,
586
593
ReceiptHandle : message . ReceiptHandle ,
587
594
} ) ) ,
0 commit comments