fix: fix worker weights handling
[poolifier.git] / src / utils.ts
index 20493767db87d80689a6cb067df3e22f72b759ce..8e84e9474c8a91d1adceb740e5c5ff21292faa02 100644 (file)
@@ -291,12 +291,12 @@ export const buildInternalWorkerChoiceStrategyOptions = (
   opts?: InternalWorkerChoiceStrategyOptions
 ): InternalWorkerChoiceStrategyOptions => {
   opts = clone(opts ?? {})
-  if (opts.weights == null) {
+  if (opts?.weights == null) {
     opts.weights = getDefaultWeights(poolMaxSize)
   }
   return {
     ...getDefaultInternalWorkerChoiceStrategyOptions(
-      poolMaxSize + Object.keys(opts?.weights ?? {}).length
+      poolMaxSize + Object.keys(opts.weights).length
     ),
     ...opts
   }