I want to write a code that capture an object asynchronously, so it needs to wait for a while. When it gets the object, it stops waiting and move on. So far this what I have:
function captureObject(obj,id) {
    var i =1;
    while (obj.value === '' && i<10) {
        i++;
        (function(i,obj) {
            setTimeout(
                function() { 
                    if(obj.value === '') {
                        // do stuff here
                        return true;
                    }
                    return false;
                },
                1000 * i
            );
        })(i,obj);
    }
}
Basically I want to achieve: if obj.value is an empty string, keep waiting until it reaches 10 seconds and return true. If within 10 seconds it gets something, return false. But the code doesn't work.
Any suggestion?
 
    