Skip to content

Commit

Permalink
system/raffles: Add clearTimeout to free gc
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed May 6, 2018
1 parent b061cb8 commit 5881374
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libs/systems/raffles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TYPE_TICKETS = 1

class Raffles {
constructor () {
this.timeouts = {}
if (global.commons.isSystemEnabled(this)) {
this.lastAnnounce = _.now()

Expand Down Expand Up @@ -144,7 +145,8 @@ class Raffles {
async announce () {
let raffle = await global.db.engine.findOne('raffles', { winner: null })
if (!await global.cache.isOnline() || _.isEmpty(raffle) || _.now() - this.lastAnnounce < (await global.configuration.getValue('raffleAnnounceInterval') * 60 * 1000)) {
setTimeout(() => this.announce(), 60000)
if (!_.isNil(this.timeouts.announce)) clearTimeout(this.timeouts.announce)
this.timeouts.announce = setTimeout(() => this.announce(), 60000)
return
}

Expand All @@ -166,7 +168,8 @@ class Raffles {
})
debug(message); global.commons.sendMessage(message, global.commons.getOwner())

setTimeout(() => this.announce(), 60000)
if (!_.isNil(this.timeouts.announce)) clearTimeout(this.timeouts.announce)
this.timeouts.announce = setTimeout(() => this.announce(), 60000)
}

async remove (self) {
Expand Down

0 comments on commit 5881374

Please sign in to comment.