JSFiddle - React, Tailwind, and code Playground
by antixrist
HTML
<script src="https://raw.githubusercontent.com/antixrist/waiter.js/master/waiter.js"></script>
JavaScript
var testIt = false;
setTimeout(function () {
testIt = true;
}, 1200); // 1.2 sec
var timeout = 2000; // 2 sec
var interval = 200 // 0.2 sec
// run waiter!
waiter(timeout, interval, function (elapsedTime, iteration) {
console.log('check!', 'testIt:', testIt, 'elapsed time:', elapsedTime +'ms', '; iteration:', iteration);
return testIt === true;
}, function (err, elapsedTime, iteration) {
if (err) {
// throw err;
console.log('Fail! Time left but condition still "false"!', 'testIt:', testIt, ';', elapsedTime +'ms', 'and', iteration, 'iteration');
return;
}
console.log('done!', 'testIt:', testIt, ';', elapsedTime +'ms', 'and', iteration, 'iteration');
});