promise-extradeprecated

Convenience methods for node promises

Usage no npm install needed!

<script type="module">
  import promiseExtra from 'https://cdn.skypack.dev/promise-extra';
</script>

README

Promise-Extra for Node.js

Build Status Coverage Status JavaScript Style Guide

Convenience methods for the native Promise implementation in Node. Gives you better flow control rather than the original Promise.all and Promise.race methods, among other goodies. This is a drop in replacement for the Promise global, and extends the original functionality.

More features coming soon! Suggest one

Getting Started

npm i --save promise-extra
const Promise = require('promise-extra')

API

Promise.waterfall (promises, initial)

Runs an array of *wrapped promises serially instead of concurrently. Resolved values cascade down the promise chain (meaning the next promise will receive the value of the previous promise). The waterfall will not continue if a promise is rejected, and that rejected error will get passed to .catch.

  • promises An array of promises. *PLEASE NOTE: It's necessary to wrap each of your promises in its own function! Otherwise they will get called immediately and the order won't be guaranteed. See the example below.

    Type: array
    Required: yes

  • initial The initial value to send through to your first promise function.

    Type: any
    Required: no
    Default: none

const initialValue = 1
const promiseChain = [
  (i) => Promise.resolve(++i), // i === 1 (from initial value)
  (i) => Promise.resolve(++i), // i === 2
  (i) => Promise.resolve(++i)  // i === 3
]

Promise.waterfall(promiseChain, initialValue)
  .then(result => /* result === 4 */ )
  .catch(error => /* first rejected promise, if any */ )

License

MIT © Jason Maurer