Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move up the #_busy flag to fix the synchronization queue error. #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/TaskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export class TaskRunner<T = any> {
#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<T>;
Expand All @@ -139,19 +141,16 @@ export class TaskRunner<T = any> {
task,
});
});

this.#_busy = true;
}
} else {
this.#_busy = false;
this.#_duration.end = Date.now();
this.#_duration.total = Math.ceil(
this.#_duration.end - this.#_duration.start
);

/* istanbul ignore next */
this.#runHook(RunnerEvents.END);

this.#_busy = false;
}
}

Expand Down