Waits for predicate to be truthy and resolves a Promise. The library provides TypeScript definitions. No dependencies needed. Please be sure that your environment has Promise support (or has a polyfill).
$ npm install async-wait-
The simple use case is described below:
const waitUntil = ;const timeOfStart = Date;// Wait for some async operation to end;
The library is async/await compatible because it uses Promises/A+, so the example above could be rewritten:
const waitUntil = ;const timeOfStart = Date;// Wait for some async operation to endtryconst result = await;// Here are the operations to be done after predicateconsole;catch error// Here are the operations to be done if predicate didn't succeed in the timeoutconsole;
/*** Waits for predicate to be truthy and resolves a Promise** @param predicate Function Predicate that checks the condition* @param timeout Number Maximum wait interval, optional, 5000ms by default* @param interval Number Wait interval, optional, 50ms by default* @return Promise Promise to return a callback result*/: Promise;
The library exports type definitions for TypeScript. As far as the library ships the code with
commonJS module support only, you have to use
import * as syntax to use it:
;;// Wait for some async operation to endtrycatch error
Library has 100% test coverage:
$ npm run test:coverage> async-wait-
Library is 100% compatible with airbnb-base for ES5.
Library has the following commands available:
Run the tests:
$ npm test
Run the tests and display test coverage:
$ npm run test:coverage
Run the linter:
$ npm run lint
No building required, library is implemented with ES5 for better compatibility and shipped as is.
Library is shipped "as is" under MIT License.
Feel free to contribute. Just raise ann issue, create a pull request covering it and don't forget to test everything properly.