Skip to content

Commit

Permalink
refactor(parallel): use clamp to simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MarlonPassos-git authored and aleclarson committed Nov 21, 2024
1 parent ceed350 commit ea7ca47
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/async/parallel.ts
Original file line number Diff line number Diff line change
@@ -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<K> = {
index: number
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function parallel<T, K>(
}
}
// 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
Expand Down

0 comments on commit ea7ca47

Please sign in to comment.