Wait for a condition to be true
Can be useful for polling.
$ npm install --save p-wait-for
const pWaitFor = require('p-wait-for');
const pathExists = require('path-exists');
pWaitFor(() => pathExists('unicorn.png')).then(() => {
console.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 a boolean
or a Promise
for a boolean
.
Type: number
Default: 20
Number of milliseconds to wait before retrying condition
.
- p-whilst - Calls a function repeatedly while a condition returns true and then resolves the promise
- More…
MIT © Sindre Sorhus