Socket
Socket
Sign inDemoInstall

p-wait-for

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    p-wait-for

Wait for a condition to be true


Version published
Weekly downloads
820K
decreased by-7.66%
Maintainers
1
Install size
16.3 kB
Created
Weekly downloads
 

Readme

Source

p-wait-for

Wait for a condition to be true

Can be useful for polling.

Install

$ npm install p-wait-for

Usage

import pWaitFor from 'p-wait-for';
import pathExists from 'path-exists';

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 with a TimeoutError.

before

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.

TimeoutError

Exposed for instance checking.

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

Keywords

FAQs

Last updated on 09 Jul 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc