p-try-each
v1.0.1
Published
Runs promise-returning functions in series but stops whenever any of the functions were successful
Downloads
5,850
Maintainers
Readme
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
.
Install
npm install --save p-try-each
Usage
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'
})();
API
pTryEach(tasks)
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.
tasks
Type: Iterable<Function>
Functions must return a value. In case of a returned promise, it will be awaited before starting with the next task.
License
MIT