p-try-each
Runs promise-returning functions in series but stops whenever any of the functions were successful
Last updated 6 years ago by pedromiguelss .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install p-try-each 
SYNC missed versions from official npm registry.

p-try-each Build Status

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

Current Tags

  • 1.0.1                                ...           latest (6 years ago)

2 Versions

  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |