Skip to content

fix: allow _onWorkerAvailable to dispatch up to concurrentTasksPerWorker - #143

Closed
feritcemkahraman wants to merge 1 commit into
tinylibs:mainfrom
feritcemkahraman:fix/drain-concurrent-tasks
Closed

feritcemkahraman wants to merge 1 commit into
tinylibs:mainfrom
feritcemkahraman:fix/drain-concurrent-tasks

Conversation

@feritcemkahraman

Copy link
Copy Markdown

Summary

Remove premature
eturn\ inside _onWorkerAvailable()'s while loop so queued tasks are dispatched up to \concurrentTasksPerWorker.

Problem

_onWorkerAvailable()\ iterates over \ askQueue\ / \skipQueue\ with:
\\ s
while (
(this.taskQueue.size > 0 || this.skipQueue.length > 0) &&
workerInfo.currentUsage() < this.options.concurrentTasksPerWorker
) { ... }
\`nHowever, the loop body previously ended with an unconditional
eturn, exiting immediately after dispatching a single task. When multiple tasks are queued and a worker has remaining concurrency capacity (or becomes available with capacity > 1), subsequent queued tasks remained in \ askQueue\ until another event or task completion occurred.

Removing
eturn\ lets the while loop continue filling the available worker up to \concurrentTasksPerWorker.

Validation

  • Added unit test in \ est/task-queue.test.ts\ verifying multiple queued tasks are concurrently dispatched to an available worker up to \concurrentTasksPerWorker.
  • \pnpm build\ (\ sdown)
  • \pnpm vitest run test/task-queue.test.ts: all 9 tests pass.
  • \pnpm typecheck\ (\ sc --noEmit): clean.
  • \pnpm lint\ (\eslint --max-warnings=0): clean.

@AriPerkkio AriPerkkio closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants