Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-chain-break

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-chain-break

PB is a simple promise flow control helper

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

logo

PromiseBreak

Description

Pb is little, but powerfull utility module made to close some gaps in JavaScript Promises. Please feel free to provide any requests to new functionality. It is based on https://github.com/petkaantonov/bluebird/issues/581 issue.

Usage

Installation

    $ npm install --save promise-chain-break
    const pb = require('promise-chain-break');

Wrapping

To make magic work you need to wrap over Promise callbacks with pb at least at one level lower then you planing to pass flow control commands and to the end of chain. But it is better for code maintance to wrap all callbacks at once.

    db.getData()
    .then(pb((data) => {
    }))
    .then(pb(() => {
    }))
    .then(pb(() => {
    }))
    .catch((error) => {
        console.error(error);
    });

Break Promise

If you need to break a chain of promises

    db.getData()
    .then(pb((data) => {
        if (!data.someCheck()) {
            tellSomeone();

            // All other '.then' calls will be skiped
            return pb.BREAK;
        }
    }))
    .then(pb(() => {
    }))
    .then(pb(() => {
    }))
    .catch((error) => {
        console.error(error);
    });

Skip Next Promise

If you decided to use one call in chain only in some cases.

    db.getData()
    .then(pb((data) => {
        if (!data.needSomeMoreDBWork) {
            // Next '.then' call will be skiped
            return pb.SKIP_NEXT;
        }
    }))
    .then(pb(() => {
        return db.doMoreStuff();
    }))
    .then(pb(() => {
    }))
    .catch((error) => {
        console.error(error);
    });

Keywords

FAQs

Package last updated on 30 Apr 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc