JSFiddle - React, Tailwind, and code Playground

by kentaromiura

JavaScript

var ok = 5;
function check(){
    if(ok == 1) return true;
    ok--;
}

var polling = function( check, after, delay ){
    var foo = function(){
        console.log('polling', ok)
        if(check()){
            after();
        }else{
            foo.delay(delay)    
        }
    };
    foo.delay(delay)
}

polling(check,
        function(){
            alert('foo')
        },
        300);