Skip to content

Commit 4ab2813

Browse files
sethpsindresorhus
andauthored
Fix error on invalid concurrency (#35)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 824edb8 commit 4ab2813

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const pTry = require('p-try');
33

44
const pLimit = concurrency => {
55
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
6-
return Promise.reject(new TypeError('Expected `concurrency` to be a number from 1 and up'));
6+
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
77
}
88

99
const queue = [];

test.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,24 @@ test('clearQueue', async t => {
138138
t.is(limit.pendingCount, 0);
139139
});
140140

141-
test('throws on invalid concurrency argument', async t => {
142-
await t.throwsAsync(pLimit(0));
143-
await t.throwsAsync(pLimit(-1));
144-
await t.throwsAsync(pLimit(1.2));
145-
await t.throwsAsync(pLimit(undefined));
146-
await t.throwsAsync(pLimit(true));
141+
test('throws on invalid concurrency argument', t => {
142+
t.throws(() => {
143+
pLimit(0);
144+
});
145+
146+
t.throws(() => {
147+
pLimit(-1);
148+
});
149+
150+
t.throws(() => {
151+
pLimit(1.2);
152+
});
153+
154+
t.throws(() => {
155+
pLimit(undefined);
156+
});
157+
158+
t.throws(() => {
159+
pLimit(true);
160+
});
147161
});

0 commit comments

Comments
 (0)