feature: allow sweeping of inactive request buckets

This commit is contained in:
Amish Shah
2018-05-02 17:57:48 +01:00
parent 745669a7c9
commit b5f37728a7
5 changed files with 35 additions and 13 deletions

View File

@@ -13,6 +13,15 @@ class RESTManager {
this.tokenPrefix = tokenPrefix;
this.versioned = true;
this.timeDifferences = [];
if (client.options.restSweepInterval > 0) {
client.setInterval(() => {
for (const handler in this.handlers) {
if (this.handlers[handler] && this.handlers[handler]._inactive) {
this.handlers[handler] = undefined;
}
}
}, client.options.restSweepInterval * 1000);
}
}
get api() {

View File

@@ -26,6 +26,13 @@ class RequestHandler {
this.handle();
}
get _inactive() {
return this.queue.length === 0 &&
!this.limited &&
Date.now() > this.resetTime &&
(typeof this.busy === 'undefined' || this.busy === false);
}
execute(item) {
return new Promise((resolve, reject) => {
const finish = timeout => {