
Company News
Socket Joins the OpenJS Foundation
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.
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.
$ npm install p-state
const timers = require('timers/promises');
const {promiseStateSync} = require('p-state');
(async () => {
const timeoutPromise = timers.setTimeout(100);
console.log(promiseStateSync(timeoutPromise));
//=> 'pending'
await timeoutPromise;
console.log(promiseStateSync(timeoutPromise));
//=> 'fulfilled'
})();
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.
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.
FAQs
Inspect the state of a promise
The npm package p-state receives a total of 733 weekly downloads. As such, p-state popularity was classified as not popular.
We found that p-state demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.