Skip to content

Commit

Permalink
eager init workers
Browse files Browse the repository at this point in the history
  • Loading branch information
sashankaryal committed Nov 22, 2024
1 parent 2af9ec6 commit 69d495a
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions app/packages/looker/src/lookers/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,12 @@ const LABELS_SET = new Set(LABELS);
const getLabelsWorker = (() => {
const numWorkers =
typeof window !== "undefined" ? navigator.hardwareConcurrency || 4 : 1;
let workers: Worker[];

let next = -1;
return () => {
if (!workers) {
workers = [];
for (let i = 0; i < numWorkers; i++) {
workers.push(createWorker(LookerUtils.workerCallbacks));
}
}
const workers = Array.from({ length: numWorkers }, () =>
createWorker(LookerUtils.workerCallbacks)
);

next++;
next %= numWorkers;
return workers[next];
};
let next = 0;
return () => workers[next++ % numWorkers];
})();

export abstract class AbstractLooker<
Expand Down

0 comments on commit 69d495a

Please sign in to comment.