🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

p-state

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-state

Inspect the state of a promise

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

p-state

Inspect the state of a promise

You would usually not need this as you can just await the promise at any time to get its value even after it's resolved. This package could be useful if you need to check the state of the promise before doing a heavy operation or for assertions when writing tests.

Vote up this issue if you want to see this feature being included in Node.js itself.

Install

npm install p-state

Usage

import timers from 'node:timers/promises';
import {promiseStateSync} from 'p-state';

const timeoutPromise = timers.setTimeout(100);

console.log(promiseStateSync(timeoutPromise));
//=> 'pending'

await timeoutPromise;

console.log(promiseStateSync(timeoutPromise));
//=> 'fulfilled'

API

promiseStateAsync(promise: Promise)

Asynchronously inspect the state of a promise.

Returns a promise for the state as a string with the possible values: 'pending', 'fulfilled', 'rejected'.

Note: While this is async, it does return the state in the next microtask, which is almost right away.

import timers from 'node:timers/promises';
import {promiseStateAsync} from 'p-state';

const timeoutPromise = timers.setTimeout(100);

console.log(await promiseStateAsync(timeoutPromise));
//=> 'pending'

await timeoutPromise;

console.log(await promiseStateAsync(timeoutPromise));
//=> 'fulfilled'

promiseStateSync(promise: Promise)

Synchronously inspect the state of a promise.

Returns the state as a string with the possible values: 'pending', 'fulfilled', 'rejected'.

Note: This method does not work in the browser.

  • p-reflect - Make a promise always fulfill with its actual fulfillment value or rejection reason
  • p-settle - Settle promises concurrently and get their fulfillment value or rejection reason
  • More…

Keywords

promise

FAQs

Package last updated on 23 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts