A promise exports
status
andvalue
(orreason
).
$ npm i -S promise-with-status
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
Returns withStatus(promise)
function.
Type: Function
Your favorite Promise
implementation
Returns new promise
having status
and other properties.
Type: Promise
A promise, howver it will be not modified.
withStatus.pending
, withStatus.fullfilled
or withStatus.rejected
If promise.status === withStatus.fullfilled
is true
, it is promise's fullfilled value.
If promise.status === withStatus.rejected
is true
, it is promise's rejected reason.
Exported symbols which means each statuses.
MIT and ๐ฃ ยฉ TSUYUSATO "MakeNowJust" Kitsune <[email protected]> 2016