Skip to content

Commit

Permalink
Minor simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 11, 2021
1 parent 11bc75d commit 5ee5d93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -10,6 +10,7 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
steps:
Expand Down
10 changes: 6 additions & 4 deletions index.js
Expand Up @@ -8,7 +8,7 @@ export default async function pMap(
stopOnError = true
} = {}
) {
return new Promise((resolve, reject) => {
return new Promise((resolve, reject_) => { // eslint-disable-line promise/param-names
if (typeof mapper !== 'function') {
throw new TypeError('Mapper function is required');
}
Expand All @@ -26,6 +26,11 @@ export default async function pMap(
let resolvingCount = 0;
let currentIndex = 0;

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

const next = () => {
if (isRejected) {
return;
Expand Down Expand Up @@ -74,7 +79,6 @@ export default async function pMap(
next();
} catch (error) {
if (stopOnError) {
isRejected = true;
reject(error);
} else {
errors.push(error);
Expand All @@ -87,7 +91,6 @@ export default async function pMap(
try {
next();
} catch (error) {
isRejected = true;
reject(error);
}
}
Expand All @@ -104,7 +107,6 @@ export default async function pMap(
try {
next();
} catch (error) {
isRejected = true;
reject(error);
break;
}
Expand Down

0 comments on commit 5ee5d93

Please sign in to comment.