promise-break
Break out of a promise chain
Last updated 3 years ago by danielkalen .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install promise-break 
SYNC missed versions from official npm registry.

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.

Related

License

MIT © Sindre Sorhus

Current Tags

  • 0.1.2                                ...           latest (3 years ago)

3 Versions

  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 6
Last Month 2
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |