predictype

predictype v0.8.1


predictype / predicates/promises / promiseState

Function: promiseState()

promiseState<T>(wrapper, oper): boolean

Defined in: predicates/promises/promiseState.ts:56

Checks the state of a wrapped Promise using the specified operation.

Note: This predicate requires a wrapper or custom Promise implementation that exposes state. Standard JS Promises do not expose their state synchronously.

Type Parameters

T

T

Parameters

wrapper

PromiseWithState<T>

The wrapped Promise with state.

oper

PromiseStateOper

The state operation to perform (e.g. ‘is_pending’, ‘is_fulfilled’).

Returns

boolean

True if the state check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const p = Promise.resolve(42);
const wrapped = wrapPromise(p);

promiseState(wrapped, 'is_pending'); // true (immediately after wrapping)

Remarks

Supported Operators: