Skip to content

Commit

Permalink
Added rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Oct 5, 2023
1 parent c058fb1 commit f648e00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/models/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ export default class Queue<T> {
}

private resize(n: number) {
const old = this.store;
this.store = new Array(n);
if (!this.length) {
// this will clear all existing items...
this.store.length = 0;
this.store.length = n;
this.start = 0;
return;
}
if (this.start > 0) {

const old = this.store;
this.store = new Array(n);
const afterStart = Math.min(
this.start + this.length,
old.length - this.start
Expand All @@ -73,9 +75,7 @@ export default class Queue<T> {
this.start = 0;
return;
}
if (this.length > 0) {
this.store.push(... old);
}
this.store.length = n;
}

}
4 changes: 2 additions & 2 deletions src/models/TaskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export default class TaskManager {
fx().then(
(r) => {
this.running.delete(fx);
setTimeout(this.processQueue, 1, this);
setTimeout(() => this.processQueue(), 1);
resolve(r);
},
(e) => {
this.running.delete(fx);
setTimeout(this.processQueue, 1, this);
setTimeout(() => this.processQueue(), 1);
reject(e);
}
);
Expand Down

0 comments on commit f648e00

Please sign in to comment.