Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

p-break

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-break

Break out of a promise chain

Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

p-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 p-break

Usage

Here the onlyRunConditional promises are skipped if conditional is falsy:

const pBreak = require('p-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.

  • p-if - Conditional promise chains
  • More…

License

MIT © Sindre Sorhus

Keywords

promise

FAQs

Package last updated on 11 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts