Package Exports
- promise-status-async
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-status-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
promise-status-async
Promise status management tool
Install
npm install promise-status-asyncUsage
const {
PromiseStatuses,
PROMISE_RESOLVED,
promiseStatus,
promiseState,
isPromiseResolved,
isPromiseNotRejected
} = require('promise-status-async');
const pendingPromise = new Promise(() => {});
const resolvedPromise = Promise.resolve('some value');
const rejectedPromise = Promise.reject('some reason');
(async function usageExample () {
console.log(await promiseStatus(pendingPromise));
// pending
console.log(await promiseStatus(rejectedPromise) === PromiseStatuses.PROMISE_REJECTED);
// true
console.log(await promiseStatus(resolvedPromise) === PROMISE_RESOLVED);
// true
console.log(await promiseState(resolvedPromise));
// {status: "resolved", value: "some value"}
console.log(await isPromiseResolved(pendingPromise));
// false
console.log(await isPromiseNotRejected(resolvedPromise));
// true
})();API
Constants
PromiseStatuses
{
PROMISE_PENDING: "pending",
PROMISE_RESOLVED: "resolved",
PROMISE_REJECTED: "rejected"
}Presents all the possible promise statuses.
PROMISE_PENDING
"pending"Presents status name for pending promise.
PROMISE_RESOLVED
"resolved"Presents status name for resolved promise.
PROMISE_REJECTED
"rejected"Presents status name for rejected promise.
Functions
promiseStatus()
async promiseStatus(
promise: Promise
): string // PROMISE_PENDING | PROMISE_RESOLVED | PROMISE_REJECTEDReturns an actual status of the promise.
promiseState()
async promiseState(
promise: Promise
): {
status: string, // PROMISE_PENDING | PROMISE_RESOLVED | PROMISE_REJECTED
[value]: any,
[reason]: any
}Describes actual state of the promise.
Predicates
isPromisePending()
async isPromisePending(
promise: Promise
): booleanTells whether promise is in pending status.
isPromiseResolved()
async isPromiseResolved(
promise: Promise
): booleanTells whether promise is in resolved status.
isPromiseRejected()
async isPromiseRejected(
promise: Promise
): booleanTells whether promise is in rejected status.
isPromiseNotPending()
async isPromiseNotPending(
promise: Promise
): booleanTells whether promise is in any status different to pending.
isPromiseNotResolved()
async isPromiseNotResolved(
promise: Promise
): booleanTells whether promise is in any status different to resolved.
isPromiseNotRejected()
async isPromiseNotRejected(
promise: Promise
): booleanTells whether promise is in any status different to rejected.