diff --git a/src/models/Queue.ts b/src/models/Queue.ts index 347b9e7..e141b84 100644 --- a/src/models/Queue.ts +++ b/src/models/Queue.ts @@ -46,14 +46,16 @@ export default class Queue { } 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 @@ -73,9 +75,7 @@ export default class Queue { this.start = 0; return; } - if (this.length > 0) { - this.store.push(... old); - } + this.store.length = n; } } diff --git a/src/models/TaskManager.ts b/src/models/TaskManager.ts index a837a2f..ec9c3e0 100644 --- a/src/models/TaskManager.ts +++ b/src/models/TaskManager.ts @@ -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); } );