Skip to content

Commit

Permalink
bypass loop delay in subscriptions if interval is met
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Jan 15, 2021
1 parent 66f7dd7 commit 5a7d6c7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/worker.js
Expand Up @@ -7,8 +7,15 @@ class Worker {

async start () {
while (!this.stopped) {
const started = Date.now()

await this.config.fetch().then(this.config.onFetch).catch(this.config.onError)
await Promise.delay(this.config.interval)

const duration = Date.now() - started

if (duration < this.config.interval) {
await Promise.delay(this.config.interval - duration)
}
}
}

Expand Down

0 comments on commit 5a7d6c7

Please sign in to comment.