Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
fail-fast: false
matrix:
node-version:
- 24
- 22
- 20
- 18
steps:
Comment on lines +13 to 16
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test across all current LTS versions.

All other changes are just formatting differences required by bumping up xo.

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function pMap(
signal,
} = {},
) {
return new Promise((resolve_, reject_) => {
return new Promise((_resolve, _reject) => {
if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
}
Expand Down Expand Up @@ -39,14 +39,14 @@ export default async function pMap(
};

const resolve = value => {
resolve_(value);
_resolve(value);
cleanup();
};

const reject = reason => {
isRejected = true;
isResolved = true;
reject_(reason);
_reject(reason);
cleanup();
};

Expand Down
7 changes: 6 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {expectType, expectAssignable} from 'tsd';
import pMap, {pMapIterable, type Options, type Mapper, pMapSkip} from './index.js';
import pMap, {
pMapIterable,
type Options,
type Mapper,
pMapSkip,
} from './index.js';

const sites = [
'https://sindresorhus.com',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"sideEffects": false,
"engines": {
"node": ">=18"
"node": ">=20.17"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency of the new xo version.

},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -52,6 +52,6 @@
"random-int": "^3.0.0",
"time-span": "^5.1.0",
"tsd": "^0.29.0",
"xo": "^0.56.0"
"xo": "^1.2.3"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main change.

}
}
34 changes: 15 additions & 19 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,15 @@ test('all pMapSkips', async t => {
test('all mappers should run when concurrency is infinite, even after stop-on-error happened', async t => {
const input = [1, async () => delay(300, {value: 2}), 3];
const mappedValues = [];
await t.throwsAsync(
pMap(input, async value => {
value = typeof value === 'function' ? await value() : value;
mappedValues.push(value);
if (value === 1) {
await delay(100);
throw new Error('Oops!');
}
}),
);
const promise = pMap(input, async value => {
value = typeof value === 'function' ? await value() : value;
mappedValues.push(value);
if (value === 1) {
await delay(100);
throw new Error('Oops!');
}
});
await t.throwsAsync(promise);
await delay(500);
t.deepEqual(mappedValues, [1, 3, 2]);
});
Expand Down Expand Up @@ -468,15 +467,12 @@ test('no unhandled rejected promises from mapper throws - infinite concurrency',
test('no unhandled rejected promises from mapper throws - concurrency 1', async t => {
const input = [1, 2, 3];
const mappedValues = [];
await t.throwsAsync(
pMap(input, async value => {
mappedValues.push(value);
await delay(100);
throw new Error(`Oops! ${value}`);
},
{concurrency: 1}),
{message: 'Oops! 1'},
);
const promise = pMap(input, async value => {
mappedValues.push(value);
await delay(100);
throw new Error(`Oops! ${value}`);
}, {concurrency: 1});
await t.throwsAsync(promise, {message: 'Oops! 1'});
t.deepEqual(mappedValues, [1]);
});

Expand Down
Loading