Skip to content

Commit

Permalink
Merge pull request #13 from MingweiSamuel/master
Browse files Browse the repository at this point in the history
add unref to setTimeout to prevent hanging
  • Loading branch information
Colorfulstan committed Jan 4, 2019
2 parents 4f4c185 + 154eb8a commit 03ada90
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions dist/RateLimit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class RateLimit {
console.log('starting resetTimeout for exceeded limit' + this._seconds * 1000, this.toString());
}
this.resetTimeout = setTimeout(() => { this.reset(); }, this._seconds * 1000);
this.resetTimeout.unref();
}
}
notifyLimiters() {
Expand Down
2 changes: 2 additions & 0 deletions dist/RateLimiter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,15 @@ class RateLimiter {
if (this.queue.length !== 0) {
const factorForEqualRights = Math.floor(Math.random() * 100);
this.intervalProcessQueue = setInterval(() => { this.processBurstQueue(); }, 1000 + factorForEqualRights);
this.intervalProcessQueue.unref();
}
}
refreshSpreadLimiter() {
this.clearTimeoutAndInterval();
this.intervalNextSpreadExecution = setInterval(() => {
this.processSpreadLimitInterval();
}, this.getSpreadInterval());
this.intervalNextSpreadExecution.unref();
}
execute(fn, onSuccess, onError) {
try {
Expand Down
4 changes: 3 additions & 1 deletion dist/RiotRateLimiter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class RiotRateLimiter {
this.limitersPerPlatformId[platformId] = {};
}
if (!this.limitersPerPlatformId[platformId][apiMethod]) {
console.log('creating sync rate limimter for ', platformId, apiMethod);
if (this.debug) {
console.log('creating sync rate limimter for ', platformId, apiMethod);
}
this.limitersPerPlatformId[platformId][apiMethod] = new RateLimiter_1.RateLimiter({
limits: [RateLimiter_1.RateLimiter.createSyncRateLimit(this.debug)],
strategy: this.strategy,
Expand Down
1 change: 1 addition & 0 deletions src/RateLimit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class RateLimit implements Comparable, RateLimitOptions {
}
// NOTE: using timeout since interval is not testable for some reason with node-ts and sinon!?
this.resetTimeout = setTimeout(() => {this.reset()}, this._seconds * 1000)
this.resetTimeout.unref()
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/RateLimiter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export class RateLimiter {
// rare case propably
const factorForEqualRights = Math.floor(Math.random() * 100)
this.intervalProcessQueue = setInterval(() => {this.processBurstQueue()}, 1000 + factorForEqualRights)
this.intervalProcessQueue.unref()
}
}

Expand All @@ -412,6 +413,7 @@ export class RateLimiter {
this.intervalNextSpreadExecution = setInterval(() => {
this.processSpreadLimitInterval()
}, this.getSpreadInterval())
this.intervalNextSpreadExecution.unref()
}

/**
Expand Down

0 comments on commit 03ada90

Please sign in to comment.