wait-as-promised
v1.0.2
Published
Easy way to wait for changes
Downloads
8
Readme
Install
$ yarn add wait-as-promised
Usage
Basic usage
const wait = require('wait-as-promised');
let value = false;
const predicate = () => value === true;
setTimeout(() => {
value = true;
}, 2000);
wait(predicate).then(() => console.log('value equals true'));
Timeout
const wait = require('wait-as-promised');
let value = false;
const predicate = () => value === true;
setTimeout(() => {
value = true;
}, 2000);
// will throw an exception with message 'function timed out after 1000 milliseconds'
wait(predicate, {timeout: 1000}).then(() => console.log('value equals true'));
Disable Timeout
const wait = require('wait-as-promised');
let value = false;
const predicate = () => value === true;
setTimeout(() => {
value = true;
}, 2000);
wait(predicate, {timeout: -1}).then(() => console.log('value equals true'));