Skip to content

Commit

Permalink
Prebind the _handleSqsResponse and _processMessage methods to use as …
Browse files Browse the repository at this point in the history
…callbacks.
  • Loading branch information
Ivo Rothschild committed Sep 11, 2015
1 parent 750479c commit 12e4c4e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
};

Expand All @@ -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();
});
Expand Down

0 comments on commit 12e4c4e

Please sign in to comment.