wait-for-es7

0.0.2 • Public • Published

wait-for-es7

WaitFor - util function which is waiting for some condition (checkFn) during timeout, checks it every interval. Rejects if condition not fulfilled.

NPM version Build Status Dependency Status Coverage percentage experimental

Install

npm install wait-for-es7 --save

or

yarn add wait-for-es7

Usage

import waitFor from "wait-for-es6";
 
const startTime = new Date().getTime();
 
await waitFor( () => startTime < new Date().getTime() - 4000, { timeout: 5000, interval: 500 } );
// Not rejected, because 4000ms < 5000ms
 
await waitFor( () => false, { timeout: 5000, interval: 500 } );
// Will reject, because checkFn always return false
 

API

async function waitFor(checkFn: () => boolean | Promise<boolean>, options: IWaitForOptions = {});
 
interface IWaitForOptions {
    timeout?: number;
    interval?: number;
}

Test

npm install
npm test

/wait-for-es7/

    Package Sidebar

    Install

    npm i wait-for-es7

    Weekly Downloads

    2,228

    Version

    0.0.2

    License

    ISC

    Unpacked Size

    184 kB

    Total Files

    15

    Last publish

    Collaborators

    • arvitaly