p-waterfall
Run promise-returning & async functions in series, each passing its result to the next
Last updated 6 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm
$ cnpm install p-waterfall 
SYNC missed versions from official npm registry.

p-waterfall Build Status

Run promise-returning & async functions in series, each passing its result to the next

Install

$ npm install p-waterfall

Usage

const pWaterfall = require('p-waterfall');

(async () => {
	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<Function>

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

License

MIT © Sindre Sorhus

Current Tags

  • 3.0.0                                ...           latest (4 years ago)

4 Versions

  • 3.0.0                                ...           4 years ago
  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           6 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org