wait-for-es7
v0.0.2
Published
WaitFor - util function which is waiting for some condition (`checkFn`) during `timeout`, checks it every `interval`. Rejects if condition not fulfilled.
Downloads
81
Readme
wait-for-es7
WaitFor - util function which is waiting for some condition (checkFn
) during timeout
, checks it every interval
. Rejects if condition not fulfilled.
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