{"id":13733368,"url":"https://github.com/sindresorhus/p-state","last_synced_at":"2025-10-10T16:16:55.791Z","repository":{"id":42504891,"uuid":"315020636","full_name":"sindresorhus/p-state","owner":"sindresorhus","description":"Inspect the state of a promise","archived":false,"fork":false,"pushed_at":"2024-03-16T18:43:38.000Z","size":26,"stargazers_count":128,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T21:25:41.407Z","etag":null,"topics":["inspect","introspection","npm-package","promise"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-11-22T11:25:34.000Z","updated_at":"2024-10-13T15:16:49.000Z","dependencies_parsed_at":"2024-05-01T16:03:14.715Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/p-state","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.2222222222222222,"last_synced_commit":"ecbe9cf07cddc6524b160f087e7eeb3e35bb850b"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/p-state/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247338531,"owners_count":20922986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inspect","introspection","npm-package","promise"],"created_at":"2024-08-03T03:00:42.009Z","updated_at":"2025-10-10T16:16:55.786Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages"],"sub_categories":[],"readme":"# p-state\n\n\u003e Inspect the state of a promise\n\nYou 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.\n\n**Vote up [this issue](https://github.com/nodejs/node/issues/40054) if you want to see this feature being included in Node.js itself.**\n\n## Install\n\n```sh\nnpm install p-state\n```\n\n## Usage\n\n```js\nimport timers from 'node:timers/promises';\nimport {promiseStateSync} from 'p-state';\n\nconst timeoutPromise = timers.setTimeout(100);\n\nconsole.log(promiseStateSync(timeoutPromise));\n//=\u003e 'pending'\n\nawait timeoutPromise;\n\nconsole.log(promiseStateSync(timeoutPromise));\n//=\u003e 'fulfilled'\n```\n\n## API\n\n### `promiseStateAsync(promise: Promise)`\n\nAsynchronously inspect the state of a promise.\n\nReturns a promise for the state as a string with the possible values: `'pending'`, `'fulfilled'`, `'rejected'`.\n\nNote: While this is async, it does return the state in the next [microtask](https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide), which is almost right away.\n\n```js\nimport timers from 'node:timers/promises';\nimport {promiseStateAsync} from 'p-state';\n\nconst timeoutPromise = timers.setTimeout(100);\n\nconsole.log(await promiseStateAsync(timeoutPromise));\n//=\u003e 'pending'\n\nawait timeoutPromise;\n\nconsole.log(await promiseStateAsync(timeoutPromise));\n//=\u003e 'fulfilled'\n```\n\n### `promiseStateSync(promise: Promise)`\n\nSynchronously inspect the state of a promise.\n\nReturns the state as a string with the possible values: `'pending'`, `'fulfilled'`, `'rejected'`.\n\nNote: This method does not work in the browser.\n\n## Related\n\n- [p-reflect](https://github.com/sindresorhus/p-reflect) - Make a promise always fulfill with its actual fulfillment value or rejection reason\n- [p-settle](https://github.com/sindresorhus/p-settle) - Settle promises concurrently and get their fulfillment value or rejection reason\n- [More…](https://github.com/sindresorhus/promise-fun)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fp-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-state/lists"}