1.0.0 • Published 6 years ago

forcible-promise v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

forcible-promise

A JavaScript es6 Promise wrapper which allows you to force either resolve or reject.

Install

forcible-promise is provided as an npm package, so you can easily install it with

npm install forcible-promise

Usage

import { forciblePromise } from 'forcible-promise'

const originalPromise = new Promise((resolve, reject) => {
  // Logic which resolves or rejects
});

// Get a forcible version of the original promise
const forcible = forciblePromise(originalPromise);

forcible
  .then(data => console.log(data))
  .catch(err => console.log(err))
  .finally(() => console.log('done'))

// Force the resolving of the forcible by calling forceResolve
// This will trigger the then of the promise
forcible.forceResolve(data)

// Force the rejection of the forcible by calling forceReject
// This will trigger the catch of the promise
forcible.forceReject(err)
1.0.0

6 years ago