All Projects → sindresorhus → P State

sindresorhus / P State

Licence: mit
Inspect the state of a promise

Programming Languages

javascript
184084 projects - #8 most used programming language
introspection
24 projects

Projects that are alternatives of or similar to P State

node-split-file
🌱 NodeJS Module to split and merge files for several purposes like transporting over unstable networks.
Stars: ✭ 33 (-69.44%)
Mutual labels:  promise, npm-package
retryx
Promise-based retry workflow library.
Stars: ✭ 21 (-80.56%)
Mutual labels:  promise, npm-package
P Queue
Promise queue with concurrency control
Stars: ✭ 1,863 (+1625%)
Mutual labels:  promise, npm-package
Emittery
Simple and modern async event emitter
Stars: ✭ 1,146 (+961.11%)
Mutual labels:  promise, npm-package
All Keys
Get all property keys of an object including non-enumerable and inherited ones
Stars: ✭ 100 (-7.41%)
Mutual labels:  npm-package
Got
🌐 Human-friendly and powerful HTTP request library for Node.js
Stars: ✭ 10,620 (+9733.33%)
Mutual labels:  npm-package
Taskorama
⚙ A Task/Future data type for JavaScript
Stars: ✭ 90 (-16.67%)
Mutual labels:  promise
Rollup Plugin Chrome Extension
A feature-rich solution for bundled Chrome extensions! 💯
Stars: ✭ 89 (-17.59%)
Mutual labels:  npm-package
Dynamodb Oop
Speak fluent DynamoDB, write code with fashion, I Promise() 😃
Stars: ✭ 104 (-3.7%)
Mutual labels:  promise
Pageres Cli
Capture website screenshots
Stars: ✭ 1,378 (+1175.93%)
Mutual labels:  npm-package
Airtap
Run TAP unit tests in 1789+ browsers.
Stars: ✭ 1,364 (+1162.96%)
Mutual labels:  npm-package
Ngx Api Utils
ngx-api-utils is a lean library of utilities and helpers to quickly integrate any HTTP API (REST, Ajax, and any other) with Angular.
Stars: ✭ 92 (-14.81%)
Mutual labels:  npm-package
Node Sonic Channel
🦉 Sonic Channel integration for Node. Used in pair with Sonic, the fast, lightweight and schema-less search backend.
Stars: ✭ 101 (-6.48%)
Mutual labels:  npm-package
Event Target Shim
An implementation of WHATWG EventTarget interface, plus few extensions.
Stars: ✭ 89 (-17.59%)
Mutual labels:  npm-package
New Github Release Url
Generate a URL for opening a new GitHub release with prefilled tag, body, and other fields
Stars: ✭ 102 (-5.56%)
Mutual labels:  npm-package
Mfetch
mfetch will provide you with a strong ability to request resource management
Stars: ✭ 90 (-16.67%)
Mutual labels:  promise
Tplink Cloud Api
A node.js npm module to remotely control TP-Link smartplugs (HS100, HS110) and smartbulbs (LB100, LB110, LB120, LB130) using their cloud web service (no need to be on the same wifi/lan)
Stars: ✭ 96 (-11.11%)
Mutual labels:  npm-package
Pd Select
vue components ,like ios 3D picker style,vue 3d 选择器组件,3D滚轮
Stars: ✭ 101 (-6.48%)
Mutual labels:  npm-package
Vue Csv Import
Vue.js component to select a CSV file, map the columns to fields, and post it somewhere.
Stars: ✭ 95 (-12.04%)
Mutual labels:  npm-package
Vue Promised
💝 Composable Promises & Promises as components
Stars: ✭ 1,325 (+1126.85%)
Mutual labels:  promise

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.

Install

$ npm install p-state

Usage

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'
})();

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.

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.

Related

  • 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…
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].