diff options
Diffstat (limited to 'node_modules/p-locate/index.js')
-rw-r--r-- | node_modules/p-locate/index.js | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/node_modules/p-locate/index.js b/node_modules/p-locate/index.js index 4bd08aad1..7461d665b 100644 --- a/node_modules/p-locate/index.js +++ b/node_modules/p-locate/index.js @@ -8,10 +8,7 @@ class EndError extends Error { } } -// The input can also be a promise, so we `Promise.resolve()` it -const testElement = (el, tester) => Promise.resolve(el).then(tester); - -// The input can also be a promise, so we `Promise.all()` them both +// the input can also be a promise, so we `Promise.all()` them both const finder = el => Promise.all(el).then(val => val[1] === true && Promise.reject(new EndError(val[0]))); module.exports = (iterable, tester, opts) => { @@ -22,13 +19,13 @@ module.exports = (iterable, tester, opts) => { const limit = pLimit(opts.concurrency); - // Start all the promises concurrently with optional limit - const items = [...iterable].map(el => [el, limit(testElement, el, tester)]); + // start all the promises concurrently with optional limit + const items = Array.from(iterable).map(el => [el, limit(() => Promise.resolve(el).then(tester))]); - // Check the promises either serially or concurrently + // check the promises either serially or concurrently const checkLimit = pLimit(opts.preserveOrder ? 1 : Infinity); - return Promise.all(items.map(el => checkLimit(finder, el))) + return Promise.all(items.map(el => checkLimit(() => finder(el)))) .then(() => {}) .catch(err => err instanceof EndError ? err.value : Promise.reject(err)); }; |