1.0.0 • Published 9 years ago
promise-with-status v1.0.0
promise-with-status

A promise exports
statusandvalue(orreason).
Install
$ npm i -S promise-with-statusUsage
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: wowAPI
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 <make.just.on@gmail.com> 2016
1.0.0
9 years ago