JSPM

promise-break

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q46456F
  • License MIT

Break out of a promise chain

Package Exports

  • promise-break

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-break) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

promise-break Build Status

Break out of a promise chain

This is an experiment. I personally wouldn't recommend this.
Feedback wanted on the issue tracker.

See "How do I break out of a promise chain?" for a better way.

Install

$ npm install --save promise-break

Usage

Here the onlyRunConditional promises are skipped if conditional is falsy:

const pBreak = require('promise-break');

alwaysRun1()
    .then(() => alwaysRun2())
    .then(conditional => conditional || pBreak('🦄'))
    .then(() => onlyRunConditional1())
    .then(() => onlyRunConditional2())
    .then(() => onlyRunConditional3())
    .then(() => onlyRunConditional4())
    .catch(pBreak.end)
    .then(console.log);
    //=> '🦄'

API

pBreak([value])

Starts the break. Any .then()'s between here and pBreak.end() are skipped.

value

Value to pass down the chain after pBreak.end().

pBreak.end

Ends the break. Make sure not to have any other .catch() handlers between pBreak() and here.

License

MIT © Sindre Sorhus