Skip to content

Commit

Permalink
Enforcing integer value for maxCurrencncy
Browse files Browse the repository at this point in the history
Original bug found by @wmertens
  • Loading branch information
jdalrymple committed Dec 13, 2023
1 parent dd30c77 commit c7e8286
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Sema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class Sema<T = string> {
throw new Error('pauseFn and resumeFn must be both set for pausing');
}

if (!Number.isInteger(maxConcurrency) || maxConcurrency < 0) {
throw new TypeError('maxConcurrency should be an integer and greater than zero');
}

this.maxConcurrency = maxConcurrency;
this.freeQ = new Deque(maxConcurrency);
this.waitingQ = new Deque(capacity);
Expand Down

0 comments on commit c7e8286

Please sign in to comment.