$ cnpm install p-try-each
Runs promise-returning functions in series but stops whenever any of the functions were successful. If all functions reject, the promise will be rejected with the error of the final task
Similar to async/tryEach.
npm install --save p-try-each
const pTryEach = require('p-try-each');
const tasks = [
() => Promise.resolve('foo'),
() => Promise.resolve('bar'),
() => Promise.resolve('baz')
]
(async () => {
const res = await pTryEach(tasks);
console.log(res);
// Logs:
// 'foo'
})();
Returns a Promise that is fulfilled with the value of the first fulfilled promise returned from calling the functions in tasks. If none is fulfilled, the promise will be rejected with the error of the final task.
Type: Iterable<Function>
Functions must return a value. In case of a returned promise, it will be awaited before starting with the next task.
MIT
Copyright 2013 - present © cnpmjs.org | Home |