mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 05:17:41 +00:00
[polling] Fix stopping polling
Bug: TelegramBot#stopPolling() fails to clear the timeout that is waiting to make the next polling request. Thus, if the method is invoked after the timeout has already been set up, once the timeout fn is executed, another request is made, before polling is stopped in the '.finally()' handler of the request!
This commit is contained in:
parent
6b4ff126f4
commit
d768749e8f
@ -32,6 +32,7 @@ class TelegramBotPolling {
|
||||
this._lastUpdate = 0;
|
||||
this._lastRequest = null;
|
||||
this._abort = false;
|
||||
this._pollingTimeout = null;
|
||||
this._polling();
|
||||
}
|
||||
|
||||
@ -43,6 +44,7 @@ class TelegramBotPolling {
|
||||
*/
|
||||
stopPolling(options = {}) {
|
||||
this._abort = true;
|
||||
clearTimeout(this._pollingTimeout);
|
||||
if (options.cancel) {
|
||||
const reason = options.reason || 'Polling stop';
|
||||
return this._lastRequest.cancel(reason);
|
||||
@ -76,7 +78,7 @@ class TelegramBotPolling {
|
||||
debug('Polling is aborted!');
|
||||
} else {
|
||||
debug('setTimeout for %s miliseconds', this.options.interval);
|
||||
setTimeout(() => this._polling(), this.options.interval);
|
||||
this._pollingTimeout = setTimeout(() => this._polling(), this.options.interval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user