promise-branch

1.2.2 • Public • Published

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);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.262latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.262
1.2.10
1.2.00
1.1.00
1.0.00

Package Sidebar

Install

npm i promise-branch

Weekly Downloads

62

Version

1.2.2

License

ISC

Last publish

Collaborators

  • danielglennross