bump jest and make tests pass

This commit is contained in:
Louis Hache committed 2020-11-13 19:11:55 +01:00
1 parent d28dc26fa3
commit 4f58d166b7
5769 files changed
+856618 -394571

No files matched your search

+31 -13
View File
@@ -8,27 +8,45 @@ 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 await it
const testElement = async (element, tester) => tester(await element);
// 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])));
const finder = async element => {
const values = await Promise.all(element);
if (values[1] === true) {
throw new EndError(values[0]);
}
module.exports = (iterable, tester, opts) => {
opts = Object.assign({
return false;
};
const pLocate = async (iterable, tester, options) => {
options = {
concurrency: Infinity,
preserveOrder: true
}, opts);
preserveOrder: true,
...options
};
const limit = pLimit(opts.concurrency);
const limit = pLimit(options.concurrency);
// Start all the promises concurrently with optional limit
const items = [...iterable].map(el => [el, limit(testElement, el, tester)]);
const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
// Check the promises either serially or concurrently
const checkLimit = pLimit(opts.preserveOrder ? 1 : Infinity);
const checkLimit = pLimit(options.preserveOrder ? 1 : Infinity);
return Promise.all(items.map(el => checkLimit(finder, el)))
.then(() => {})
.catch(err => err instanceof EndError ? err.value : Promise.reject(err));
try {
await Promise.all(items.map(element => checkLimit(finder, element)));
} catch (error) {
if (error instanceof EndError) {
return error.value;
}
throw error;
}
};
module.exports = pLocate;
// TODO: Remove this for the next major release
module.exports.default = pLocate;