-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86ff396
commit 82b3ffb
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,33 @@ | ||
# forcible-promise | ||
A es6 Promise wrapper which allows you to force either resolve or reject | ||
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 | ||
```bash | ||
npm install forcible-promise | ||
``` | ||
|
||
## Usage | ||
```javascript | ||
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters