From ea7ca472093030c445f34b467e09dd1fbc5fa221 Mon Sep 17 00:00:00 2001 From: marlonpassos Date: Sun, 8 Sep 2024 17:55:29 +0000 Subject: [PATCH] refactor(parallel): use clamp to simplify logic --- src/async/parallel.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/async/parallel.ts b/src/async/parallel.ts index 4bd4f11a..81e4eef0 100644 --- a/src/async/parallel.ts +++ b/src/async/parallel.ts @@ -1,4 +1,4 @@ -import { AggregateError, flat, fork, list, sort, tryit } from 'radashi' +import { AggregateError, clamp, flat, fork, list, sort, tryit } from 'radashi' type WorkItemResult = { index: number @@ -52,7 +52,7 @@ export async function parallel( } } // Create queues - const queues = list(1, Math.min(Math.max(limit, 1), array.length)).map( + const queues = list(1, clamp(limit, 1, array.length)).map( () => new Promise(processor), ) // Wait for all queues to complete