Gathering detailed insights and metrics for p-wait-for
Gathering detailed insights and metrics for p-wait-for
Gathering detailed insights and metrics for p-wait-for
Gathering detailed insights and metrics for p-wait-for
npm install p-wait-for
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.6
Supply Chain
99.4
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (86.01%)
TypeScript (13.99%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
158 Stars
35 Commits
19 Forks
7 Watchers
1 Branches
9 Contributors
Updated on Mar 09, 2025
Latest Version
5.0.2
Package Id
p-wait-for@5.0.2
Unpacked Size
8.97 kB
Size
3.27 kB
File Count
5
NPM Version
9.2.0
Node Version
16.16.0
Published on
Mar 30, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Wait for a condition to be true
Can be useful for polling.
1npm install p-wait-for
1import pWaitFor from 'p-wait-for'; 2import {pathExists} from 'path-exists'; 3 4await pWaitFor(() => pathExists('unicorn.png')); 5console.log('Yay! The file now exists.');
Returns a Promise
that resolves when condition
returns true
. Rejects if condition
throws or returns a Promise
that rejects.
Type: Function
Expected to return Promise<boolean> | boolean
.
Type: object
Type: number
Default: 20
Number of milliseconds to wait after condition
resolves to false
before calling it again.
Type: number | TimeoutOptions
Default: Infinity
Number of milliseconds to wait before automatically rejecting with a TimeoutError
.
You can customize the timeout Error
by specifying TimeoutOptions
.
1import pWaitFor from 'p-wait-for'; 2import {pathExists} from 'path-exists'; 3 4const originalSetTimeout = setTimeout; 5const originalClearTimeout = clearTimeout; 6 7sinon.useFakeTimers(); 8 9await pWaitFor(() => pathExists('unicorn.png'), { 10 timeout: { 11 milliseconds: 100, 12 message: new MyError('Time’s up!'), 13 customTimers: { 14 setTimeout: originalSetTimeout, 15 clearTimeout: originalClearTimeout 16 } 17 } 18}); 19 20console.log('Yay! The file now exists.');
Type: number
Default: Infinity
Milliseconds before timing out.
Passing Infinity
will cause it to never time out.
Type: string | Error
Default: 'Promise timed out after 50 milliseconds'
Specify a custom error message or error.
If you do a custom error, it's recommended to sub-class TimeoutError
.
Type: object
with function properties setTimeout
and clearTimeout
Custom implementations for the setTimeout
and clearTimeout
functions.
Useful for testing purposes, in particular to work around sinon.useFakeTimers()
.
Type: Function
Do something other than rejecting with an error on timeout.
Example:
1import pWaitFor from 'p-wait-for'; 2import {pathExists} from 'path-exists'; 3 4await pWaitFor(() => pathExists('unicorn.png'), { 5 timeout: { 6 milliseconds: 50, 7 fallback: () => { 8 console.log('Time’s up! executed the fallback function!'); 9 }, 10 } 11});
Type: boolean
Default: true
Whether to run the check immediately rather than starting by waiting interval
milliseconds.
Useful for when the check, if run immediately, would likely return false
. In this scenario, set before
to false
.
Resolve the main promise with a custom value.
1import pWaitFor from 'p-wait-for'; 2import pathExists from 'path-exists'; 3 4const path = await pWaitFor(async () => { 5 const path = getPath(); 6 return await pathExists(path) && pWaitFor.resolveWith(path); 7}); 8 9console.log(path);
Exposed for instance checking.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More