I've a function that, once called, calls another(synchronous) that creates a tab, then waits(asynchronously) two conditions to be true before executing another function(that should load content to the new tab).
I've tried to make the function asynchronous and to find ways to "pause" its execution until the conditions are true.
var onChosenFileToOpen = function(theFileEntry) {
$('.nav-tabs li:nth-child(' + $(".nav-tabs").children().length + ') a').click(); //synchronous function that creates a tab
var checker=setInterval(()=>{
if(currentiframe.contentWindow && currentiframe.contentWindow.editor){//waits those 2 conditions to be true
currentiframe.contentWindow.readFileIntoEditor(theFileEntry)//content is loaded to that tab
clearInterval(checker)
}
},1)};
This works fine when someone manually(through clicking a button/menu) executes that function. But if it's called multiple times at once, many tabs are created and only the last one loads the content. I need a way to wait the first call of said function to completly end before running the next ones.