promise-with-status
v1.0.0
Published
A promise exports status and value (or reason)
Downloads
2
Maintainers
Readme
promise-with-status
A promise exports
status
andvalue
(orreason
).
Install
$ npm i -S promise-with-status
Usage
const withStatus = require('promise-with-status')(Promise)
// or: const withStatus = require('promise-with-status')(require('your-favorite-promise-lib'))
const promise = withStatus(Promise.resolve(123))
console.log(promise.status) //=> Symbol(pending)
promise.then(() => console.log(promise.status)) //=> Symbol(fullfilled)
promise.then(() => console.log(promise.value)) //=> 123
const error = withStatus(Promise.reject(new Error('wow')))
error.then(() => console.log(promise.status)) //=> Symbol(rejected)
error.then(() => console.log(promise.reason)) //=> Error: wow
API
require('with-promise-status')(Promise)
Returns withStatus(promise)
function.
Promise
Type: Function
Your favorite Promise
implementation
withStatus(promise)
Returns new promise
having status
and other properties.
promise
Type: Promise
A promise, howver it will be not modified.
promise.status
withStatus.pending
, withStatus.fullfilled
or withStatus.rejected
promise.value
If promise.status === withStatus.fullfilled
is true
, it is promise's fullfilled value.
promise.reason
If promise.status === withStatus.rejected
is true
, it is promise's rejected reason.
withStatus.pending, withStatus.fullfilled, withStatus.rejected
Exported symbols which means each statuses.
License
MIT and :sushi: © TSUYUSATO "MakeNowJust" Kitsune <[email protected]> 2016