Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/p-waterfall
Run promise-returning & async functions in series, each passing its result to the next
https://github.com/sindresorhus/p-waterfall
Last synced: about 1 month ago
JSON representation
Run promise-returning & async functions in series, each passing its result to the next
- Host: GitHub
- URL: https://github.com/sindresorhus/p-waterfall
- Owner: sindresorhus
- License: mit
- Created: 2016-11-22T07:34:00.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T06:43:12.000Z (over 3 years ago)
- Last Synced: 2024-05-22T18:05:48.807Z (6 months ago)
- Language: TypeScript
- Size: 16.6 KB
- Stars: 73
- Watchers: 6
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- promise-fun - p-waterfall - returning & async functions in series, each passing its result to the next (Packages)
README
# p-waterfall
> Run promise-returning & async functions in series, each passing its result to the next
## Install
```
$ npm install p-waterfall
```## Usage
```js
import pWaterfall from 'p-waterfall';const tasks = [
initialValue => getEmoji(initialValue),
previousValue => `I β€οΈ ${previousValue}`
];console.log(await pWaterfall(tasks, 'unicorn'));
//=> 'I β€οΈ π¦'
```## API
### pWaterfall(tasks, initialValue?)
Returns a `Promise` that is fulfilled when all promises returned from calling the functions in `tasks` are fulfilled, or rejects if any of the promises reject. The fulfilled value is the value returned from the last task.
#### tasks
Type: `Iterable`
Functions are expected to return a value. If a `Promise` is returned, it's awaited before continuing with the next task.
#### initialValue
Type: `unknown`
Value to use as `previousValue` in the first task.
## Related
- [p-series](https://github.com/sindresorhus/p-series) - Run promise-returning & async functions in series
- [p-each-series](https://github.com/sindresorhus/p-each-series) - Iterate over promises serially
- [Moreβ¦](https://github.com/sindresorhus/promise-fun)---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.