New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

promise-branch

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-branch

Allows isolated branching of promise flows

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

promise-branch

Allows isolated branching of promise flows.

This lib helps to address some of the issues raised by: Broken Promises

Install

npm install --save promise-branch

API

branch(target, onResolved, onRejected)

promise-branch will ensure a rejected promise which occured before branching the flow is ignored and proxied on down the main promise chain. This means the error handler of promise-branch will only handle a rejected promise caused by the target promise/ promise factory.

  • target (Promise|Function): a promise or function that returns a promise.
  • onResolved (Function): a function that returns a promise. This is called if target resolves.
  • onRejected (Function): a function that returns a promise. This is called if target rejects.

Example

const branch = requires('promise-branch');

initialAsyncWork()
.then(() => 
  branch(
    secondaryAsyncWork(), // this can be a promise, or a function that returns a promise
    successHandler,
    errorHandler // this only handles a rejection from secondaryAsyncWork
  )
)
.then(continuedAsyncWork)
.catch(errorAsyncWork);

Keywords

FAQs

Package last updated on 13 Dec 2017

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