JSFiddle - React, Tailwind, and code Playground

by tonyleeper

JavaScript

function asyncWaitUntil(context, fn, args, predicate) {
    if (!predicate()) {
        setTimeout(function () {
            console.log("waiting");
            asyncWaitUntil.apply(context, arguments);
        }, 100);
    }
    
    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");