There is a global variable window.listNodes that is an array. This variable is refreshed each 3 seconds and is filled sequentially.
Another function onOpen() is triggered by the user and needs to have the global variable window.listNodes containing 3 elements, not less.
What I seek to do: if the global variable has not a .length equal to 3 then the program waits that the other part of the code fills window.listNodes and then begin again the function onOpen().
socket.onopen = function onOpen() {
if (window.listNodes.length === 3) {
// Do something
} else {
// Wait and when window.listNodes.length === 3:
onOpen();
}
});
};
Is there an easy way to do it? I tried with the function setTimeOut() and with a generator function and the keyword yield but I failed.
Thank you for your precious help :)
setTimeOutI showed in my answer how this can be accomplished withsetTimeout. How did you do it?