Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 4, 2023
1 parent d1e701f commit d4252da
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 176 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
12 changes: 4 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// TODO: Use the built-in type when TS 4.5 is out.
type Awaited<ValueType> = ValueType extends undefined ? ValueType : ValueType extends PromiseLike<infer ResolveValueType> ? ResolveValueType : ValueType;

// https://github.com/microsoft/TypeScript/blob/582e404a1041ce95d22939b73f0b4d95be77c6ec/lib/lib.es2020.promise.d.ts#L21-L31
export type PromiseSettledResult<ResolveValueType> = {
status: 'fulfilled';
Expand All @@ -10,7 +7,7 @@ export type PromiseSettledResult<ResolveValueType> = {
reason: unknown;
};

export interface Options {
export type Options = {
/**
The number of concurrently pending promises. Minimum: `1`.
Expand All @@ -21,13 +18,12 @@ export interface Options {
@default Infinity
*/
readonly concurrency: number;
}
};

export type PromiseFactory<ValueType> = () => PromiseLike<ValueType>;

export type ProgressNotifier = (progress: number) => void;

// @ts-expect-error `Promise.all` currently uses an incompatible combinatorics-based type definition (https://github.com/microsoft/TypeScript/issues/39788)
export class PProgress<ValueType> extends Promise<ValueType> { // eslint-disable-line @typescript-eslint/naming-convention
/**
Convenience method to run multiple promises and get a total progress of all of them. It counts normal promises with progress `0` when pending and progress `1` when resolved. For `PProgress` type promises, it listens to their `onProgress()` method for more fine grained progress reporting. You can mix and match normal promises and `PProgress` promises.
Expand Down Expand Up @@ -231,10 +227,10 @@ const runJob = async name => pProgress(async progress => {
const job = new Job(name);
job.on('data', data => {
progress(data.length / job.totalSize)
progress(data.length / job.totalSize);
});
await job.run()
await job.run();
});
const progressPromise = runJob('Gather rainbows');
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class PProgress extends Promise {
return this;
}

then(onFulfilled, onRejected) {
then(onFulfilled, onRejected) { // eslint-disable-line unicorn/no-thenable
const child = super.then(onFulfilled, onRejected);
this._listeners.add(progress => {
child._setProgress(progress);
Expand Down
Loading

0 comments on commit d4252da

Please sign in to comment.