1.0.0 • Published 8 years ago

promise-with-status v1.0.0

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

promise-with-status npm Travis SUSHI-WARE LICENSE

A promise exports status and value (or reason).

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 <make.just.on@gmail.com> 2016