Skip to content
Wait for a condition to be true
JavaScript TypeScript
Branch: master
Clone or download
Latest commit d4aca6d Apr 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Require Node.js 6 Jul 29, 2018
.gitattributes Require Node.js 6 Jul 29, 2018
.gitignore
.npmrc Require Node.js 6 Jul 29, 2018
.travis.yml Require Node.js 8, add TypeScript definition (#8) Mar 19, 2019
index.d.ts Refactor TypeScript definition to CommonJS compatible export (#9) Apr 2, 2019
index.js Refactor TypeScript definition to CommonJS compatible export (#9) Apr 2, 2019
index.test-d.ts Refactor TypeScript definition to CommonJS compatible export (#9) Apr 2, 2019
license Require Node.js 6 Jul 29, 2018
package.json 3.1.0 Apr 2, 2019
readme.md Meta tweaks Mar 19, 2019
test.js Require Node.js 8, add TypeScript definition (#8) Mar 19, 2019

readme.md

p-wait-for Build Status

Wait for a condition to be true

Can be useful for polling.

Install

$ npm install p-wait-for

Usage

const pWaitFor = require('p-wait-for');
const pathExists = require('path-exists');

(async () => {
	await pWaitFor(() => pathExists('unicorn.png'));
	console.log('Yay! The file now exists.');
})();

API

pWaitFor(condition, [options])

Returns a Promise that resolves when condition returns true. Rejects if condition throws or returns a Promise that rejects.

condition

Type: Function

Expected to return Promise<boolean> | boolean.

options

Type: Object

interval

Type: number
Default: 20

Number of milliseconds to wait before retrying condition.

timeout

Type: number
Default: Infinity

Number of milliseconds to wait before automatically rejecting.

Related

  • p-whilst - Calls a function repeatedly while a condition returns true and then resolves the promise
  • More…

License

MIT © Sindre Sorhus

You can’t perform that action at this time.