This is not GitHub.com

Like what you see? Install OctoLinker now!

Skip to content
Permalink
Browse files
Minor simplification
  • Loading branch information
sindresorhus committed Sep 11, 2021
1 parent 11bc75d commit 5ee5d9370053e148741c394586c1a8c4086da622
Showing with 7 additions and 4 deletions.
  1. +1 −0 .github/workflows/main.yml
  2. +6 −4 index.js
@@ -10,6 +10,7 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
steps:
@@ -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');
}
@@ -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;
@@ -74,7 +79,6 @@ export default async function pMap(
next();
} catch (error) {
if (stopOnError) {
isRejected = true;
reject(error);
} else {
errors.push(error);
@@ -87,7 +91,6 @@ export default async function pMap(
try {
next();
} catch (error) {
isRejected = true;
reject(error);
}
}
@@ -104,7 +107,6 @@ export default async function pMap(
try {
next();
} catch (error) {
isRejected = true;
reject(error);
break;
}

0 comments on commit 5ee5d93

Please sign in to comment.