diff --git a/src/TaskRunner.ts b/src/TaskRunner.ts index 7294d8f..971c27d 100644 --- a/src/TaskRunner.ts +++ b/src/TaskRunner.ts @@ -123,6 +123,8 @@ export class TaskRunner { #run() { if (this.#completed !== this.#total) { if (!this.#_paused && this.#running < this.#_concurrency) { + this.#_busy = true; + const difference = this.#_concurrency - this.#running; const tasks = this.#_pending.removeRange(0, difference) as Tasks; @@ -139,10 +141,9 @@ export class TaskRunner { task, }); }); - - this.#_busy = true; } } else { + this.#_busy = false; this.#_duration.end = Date.now(); this.#_duration.total = Math.ceil( this.#_duration.end - this.#_duration.start @@ -150,8 +151,6 @@ export class TaskRunner { /* istanbul ignore next */ this.#runHook(RunnerEvents.END); - - this.#_busy = false; } }