Skip to content

Commit

Permalink
fix(utils): fixes in createParalellRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
kedrzu committed Apr 9, 2024
1 parent da77580 commit 8e09d1f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/utils/src/createParalellRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ export function createParalellRunner(options: ParalelllRunnerOptions) {
let active = 0;
let done = true;

for (let i = 0; i < concurrency; i++) {
void startThread();
}

return {
start,
stop,
wait,
};

async function start() {
Expand All @@ -40,19 +37,25 @@ export function createParalellRunner(options: ParalelllRunnerOptions) {
await promise?.promise;
}

async function wait() {
await promise?.promise;
}

async function startThread() {
active++;

// eslint-disable-next-line no-constant-condition
while (true) {
if (done) {
stopThread();
return;
}

try {
const result = await handler();
if (result === false) {
stopThread();
return;
}
} catch (e) {
active--;
Expand Down

0 comments on commit 8e09d1f

Please sign in to comment.