diff --git a/lib/poller.js b/lib/poller.js index 465d41f3..5c56e5d4 100644 --- a/lib/poller.js +++ b/lib/poller.js @@ -41,7 +41,7 @@ class Poller { this._namespace = namespace this._secretDescriptor = secretDescriptor this._ownerReference = ownerReference - this._interval = null + this._timeoutId = null } /** @@ -138,13 +138,17 @@ class Poller { } } + /** + * Sets a timeout for the next poll + * @param {number} nextPollIn - Trigger poll in this many miliseconds + */ _setNextPoll (nextPollIn = this._intervalMilliseconds) { - if (this._interval) { - clearTimeout(this._interval) - this._interval = null + if (this._timeoutId) { + clearTimeout(this._timeoutId) + this._timeoutId = null } - this._interval = setTimeout(this._poll.bind(this), nextPollIn) + this._timeoutId = setTimeout(this._poll.bind(this), nextPollIn) this._logger.debug('Next poll for %s in %s in %s', this._secretDescriptor.name, this._namespace, nextPollIn) } @@ -154,7 +158,7 @@ class Poller { * @returns {Object} Poller instance. */ start ({ forcePoll = false } = {}) { - if (this._interval) return this + if (this._timeoutId) return this this._logger.debug('starting poller') @@ -172,10 +176,13 @@ class Poller { * @returns {Object} Poller instance. */ stop () { - if (!this._interval) return this + if (!this._timeoutId) return this + this._logger.debug('stopping poller') - clearTimeout(this._interval) - this._interval = null + + clearTimeout(this._timeoutId) + this._timeoutId = null + return this } }