p-whilst
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    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 of whether to execute action.

    action

    Type: Function

    Action to run for each iteration.

    You can return a promise and it will be handled.

    Related

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

    Install

    npm i p-whilst

    DownloadsWeekly Downloads

    10,342

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    4.14 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar