From 69d495a5f517f47987904b1b647383861d9b1f92 Mon Sep 17 00:00:00 2001 From: Sashank Aryal Date: Fri, 22 Nov 2024 16:50:43 -0600 Subject: [PATCH] eager init workers --- app/packages/looker/src/lookers/abstract.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/app/packages/looker/src/lookers/abstract.ts b/app/packages/looker/src/lookers/abstract.ts index 7d18e8bddb3..e0aea9aa6ba 100644 --- a/app/packages/looker/src/lookers/abstract.ts +++ b/app/packages/looker/src/lookers/abstract.ts @@ -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<