JSFiddle - React, Tailwind, and code Playground
by tonyleeper
JavaScript
function asyncWaitUntil(context, fn, args, predicate) {
if (!predicate()) {
setTimeout(function () {
console.log("waiting");
asyncWaitUntil.call(arguments);
}, 100);
return;
}
fn.apply(context, args);
}
var c;
setTimeout(function () { c = 5; }, 5000);
function add(a, b) {
asyncWaitUntil(this, add, arguments, function () { return c !== null; });
console.log("a + b + c = " + (a + b));
}
console.log("start");
add(1, 2);
console.log("end");