Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 2, 2021
1 parent 2ffd594 commit 9e94070
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bench.ts
Expand Up @@ -32,7 +32,7 @@ suite
for (let i = 0; i < 100; i++) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
queue.add(async () => {}, {
priority: (Math.random() * 100) | 0
priority: Math.trunc(Math.random() * 100)
});
}

Expand Down
20 changes: 10 additions & 10 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"funding": "https://github.com/sponsors/sindresorhus",
"main": "dist/index.js",
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"build": "del dist && tsc",
Expand Down Expand Up @@ -42,25 +42,25 @@
"bluebird"
],
"dependencies": {
"eventemitter3": "^4.0.4",
"p-timeout": "^3.2.0"
"eventemitter3": "^4.0.7",
"p-timeout": "^4.1.0"
},
"devDependencies": {
"@sindresorhus/tsconfig": "^0.7.0",
"@types/benchmark": "^1.0.33",
"@types/node": "^14.6.0",
"ava": "^2.0.0",
"@types/benchmark": "^2.1.0",
"@types/node": "^14.14.19",
"ava": "^2.4.0",
"benchmark": "^2.1.4",
"codecov": "^3.7.2",
"codecov": "^3.8.1",
"del-cli": "^3.0.1",
"delay": "^4.4.0",
"in-range": "^2.0.0",
"nyc": "^15.1.0",
"random-int": "^2.0.1",
"time-span": "^4.0.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.2",
"xo": "^0.33.0"
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"xo": "^0.37.1"
},
"ava": {
"babel": false,
Expand Down
13 changes: 8 additions & 5 deletions source/index.ts
Expand Up @@ -60,9 +60,9 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
options = {
carryoverConcurrencyCount: false,
intervalCap: Infinity,
intervalCap: Number.POSITIVE_INFINITY,
interval: 0,
concurrency: Infinity,
concurrency: Number.POSITIVE_INFINITY,
autoStart: true,
queueClass: PriorityQueue,
...options
Expand All @@ -77,7 +77,7 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
}

this._carryoverConcurrencyCount = options.carryoverConcurrencyCount!;
this._isIntervalIgnored = options.intervalCap === Infinity || options.interval === 0;
this._isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
this._intervalCap = options.intervalCap;
this._interval = options.interval;
this._queue = new options.queueClass!();
Expand Down Expand Up @@ -251,8 +251,11 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
return undefined;
}
);

// TODO: Fix this ignore.
// @ts-expect-error
resolve(await operation);
} catch (error) {
} catch (error: unknown) {
reject(error);
}

Expand Down Expand Up @@ -358,7 +361,7 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
*/
sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number {
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
// eslint-disable-next-line unicorn/no-array-callback-reference
return this._queue.filter(options).length;
}

Expand Down
2 changes: 1 addition & 1 deletion source/lower-bound.ts
Expand Up @@ -5,7 +5,7 @@ export default function lowerBound<T>(array: readonly T[], value: T, comparator:
let count = array.length;

while (count > 0) {
const step = (count / 2) | 0;
const step = Math.trunc(count / 2);
let it = first + step;

if (comparator(array[it], value) <= 0) {
Expand Down
4 changes: 1 addition & 3 deletions source/options.ts
@@ -1,8 +1,6 @@
import {Queue, RunFunction} from './queue';

export interface QueueAddOptions {
readonly [key: string]: unknown;
}
export type QueueAddOptions = Readonly<Record<string, unknown>>;

export interface Options<QueueType extends Queue<RunFunction, QueueOptions>, QueueOptions extends QueueAddOptions> {
/**
Expand Down
17 changes: 8 additions & 9 deletions test/test.ts
Expand Up @@ -47,7 +47,7 @@ test('.add() - concurrency: 1', async t => {
return value;
});

// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
// eslint-disable-next-line unicorn/no-array-callback-reference
t.deepEqual(await Promise.all(input.map(mapper)), [10, 20, 30]);
t.true(inRange(end(), {start: 590, end: 650}));
});
Expand Down Expand Up @@ -227,12 +227,11 @@ test('.onIdle()', async t => {

test('.onIdle() - no pending', async t => {
const queue = new PQueue();

t.is(queue.size, 0);
t.is(queue.pending, 0);

const promise = await queue.onIdle();
t.is(promise, undefined);
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
t.is(await queue.onIdle(), undefined);
});

test('.clear()', t => {
Expand Down Expand Up @@ -283,7 +282,7 @@ test('enforce number in options.concurrency', t => {
});

t.notThrows(() => {
new PQueue({concurrency: Infinity});
new PQueue({concurrency: Number.POSITIVE_INFINITY});
});
});

Expand Down Expand Up @@ -312,7 +311,7 @@ test('enforce number in queue.concurrency', t => {
});

t.notThrows(() => {
(new PQueue()).concurrency = Infinity;
(new PQueue()).concurrency = Number.POSITIVE_INFINITY;
});
});

Expand Down Expand Up @@ -340,7 +339,7 @@ test('enforce number in options.intervalCap', t => {
});

t.notThrows(() => {
new PQueue({intervalCap: Infinity});
new PQueue({intervalCap: Number.POSITIVE_INFINITY});
});
});

Expand All @@ -360,7 +359,7 @@ test('enforce finite in options.interval', t => {
);

t.throws(() => {
new PQueue({interval: Infinity});
new PQueue({interval: Number.POSITIVE_INFINITY});
});

t.notThrows(() => {
Expand All @@ -372,7 +371,7 @@ test('enforce finite in options.interval', t => {
});

t.throws(() => {
new PQueue({interval: Infinity});
new PQueue({interval: Number.POSITIVE_INFINITY});
});
});

Expand Down

0 comments on commit 9e94070

Please sign in to comment.