Skip to content

Commit 0612ae8

Browse files
authored
Merge pull request #390 from autonomys/add-validation-sem
Add validation to `weightedRequestConcurrencyController`
2 parents 3652b0b + adbcc31 commit 0612ae8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/utility/asynchronous/src/concurrency/weightedRequestsConcurrencyController.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export const weightedRequestConcurrencyController = (
5353
}
5454

5555
const runJob = async <T>(job: Job<T>, concurrency: number): Promise<T> => {
56+
if (concurrency < 0) {
57+
throw new Error('Concurrency must be greater than 0')
58+
}
59+
if (concurrency > maxConcurrency) {
60+
throw new Error('Concurrency must be less than or equal to max concurrency')
61+
}
62+
5663
const exceededMaxConcurrency = active + concurrency > maxConcurrency
5764
const shouldRespectOrder = ensureOrder && queue.length > 0
5865
if (exceededMaxConcurrency || shouldRespectOrder) {

0 commit comments

Comments
 (0)