From 12e4c4e769aa2c743ae17f3f5641275e31fa914a Mon Sep 17 00:00:00 2001 From: Ivo Rothschild Date: Fri, 11 Sep 2015 16:55:03 -0500 Subject: [PATCH] Prebind the _handleSqsResponse and _processMessage methods to use as callbacks. --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7b36261d..bcc044b8 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,9 @@ function Consumer(options) { this.sqs = options.sqs || new AWS.SQS({ region: options.region || 'eu-west-1' }); + + this._handleSqsResponseBound = this._handleSqsResponse.bind(this); + this._processMessageBound = this._processMessage.bind(this); } util.inherits(Consumer, EventEmitter); @@ -83,7 +86,7 @@ Consumer.prototype._poll = function () { if (!this.stopped) { debug('Polling for messages'); - this.sqs.receiveMessage(receiveParams, this._handleSqsResponse.bind(this)); + this.sqs.receiveMessage(receiveParams, this._handleSqsResponseBound); } }; @@ -96,7 +99,7 @@ Consumer.prototype._handleSqsResponse = function (err, response) { debug(response); if (response && response.Messages && response.Messages.length > 0) { - async.each(response.Messages, this._processMessage.bind(this), function () { + async.each(response.Messages, this._processMessageBound, function () { // start polling again once all of the messages have been processed consumer._poll(); });