From 7e6c220aa3c354390b80ee8b1cc8c8c23f7692d7 Mon Sep 17 00:00:00 2001 From: Yago Date: Mon, 11 Jan 2016 18:49:02 +0100 Subject: [PATCH] Binds in TelegramBotPolling.prototype._polling --- src/telegramPolling.js | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/telegramPolling.js b/src/telegramPolling.js index 75ee46c..e2c794d 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -25,30 +25,30 @@ var TelegramBotPolling = function (token, options, callback) { }; TelegramBotPolling.prototype._polling = function () { - var self = this; - - this.lastRequest = this._getUpdates().then(function (updates) { - self.lastUpdate = Date.now(); - debug('polling data %j', updates); - updates.forEach(function (update, index) { - // If is the latest, update the offset. - if (index === updates.length - 1) { - self.offset = update.update_id; - debug('updated offset: %s', self.offset); + this.lastRequest = this._getUpdates() + .then(function (updates) { + this.lastUpdate = Date.now(); + debug('polling data %j', updates); + updates.forEach(function (update, index) { + // If is the latest, update the offset. + if (index === updates.length - 1) { + this.offset = update.update_id; + debug('updated offset: %s', this.offset); + } + this.callback(update); + }); + }.bind(this)) + .catch(function (err) { + debug('polling error: %j', err); + }) + .finally(function () { + if (this.abort) { + debug('Polling is aborted!'); + } else { + debug('setTimeout for %s miliseconds', this.interval); + setTimeout(this._polling.bind(this), this.interval); } - self.callback(update); - }); - }).catch(function (err) { - debug('polling error: %j', err); - }).finally(function () { - if (self.abort) { - debug('Polling is aborted!'); - return; - } - - debug('setTimeout for %s miliseconds', self.interval); - setTimeout(self._polling.bind(self), self.interval); - }); + }.bind(this)); }; TelegramBotPolling.prototype._getUpdates = function () {