Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-whilst

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-whilst

While a condition returns true, calls a function repeatedly, and then resolves the promise

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

p-whilst

While a condition returns true, calls a function repeatedly, and then resolves the promise

Think async version of the while statement.

Install

$ npm install p-whilst

Usage

import pWhilst from 'p-whilst';

let count = 0;

await pWhilst(
	() => count < 5,
	() => count++
);

console.log(count);
//=> 5

API

pWhilst(condition, action)

While condition returns true, executes action repeatedly, and then resolves the promise. Rejects if action returns a promise that rejects or if an error is thrown anywhere.

condition

Type: Function
Arguments: The value the action function returns

Expected to return a boolean or a Promise<boolean> that indicates whether to execute action.

action

Type: Function

Action to run for each iteration.

You can return a promise and it will be handled.

  • p-do-whilst - Calls a function repeatedly while a condition returns true and then resolves the promise
  • p-forever - Run promise-returning & async functions repeatedly until you end it
  • p-wait-for - Wait for a condition to be true
  • More…

Keywords

FAQs

Package last updated on 21 Jul 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc