Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
fix: rename interval to timeoutId
Browse files Browse the repository at this point in the history
  • Loading branch information
Flydiverny committed Jul 23, 2019
1 parent bc8e395 commit 504c7ee
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Poller {
this._namespace = namespace
this._secretDescriptor = secretDescriptor
this._ownerReference = ownerReference
this._interval = null
this._timeoutId = null
}

/**
Expand Down Expand Up @@ -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)
}

Expand All @@ -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')

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

0 comments on commit 504c7ee

Please sign in to comment.