Worried about a possbile race condition
I'm a bit concerned that an app I'm working on may have a race condition that I won't be able to test.
The main code looks like this:
Code:
wlc.scorm.LMSInitialize = function(p) {
this.getAPI(p);
return this.API.LMSInitialize(p);
};
The getAPI funciton looks like this:
Code:
wlc.scorm.getAPI = function() {
function searchWin(win) {
while((win.API == null) && (win.parent != null) && (win.parent != win) && (wlc.scorm.findAttempts <= wlc.scorm.findLimit)){
wlc.scorm.findAttempts++;
win = win.parent;
}
if (win.API != null) {
return win.API;
} else {
return null;
}
}
this.API = searchWin(window);
if( (this.API == null) && (window.opener != null) && (typeof(window.opener) != "undefined") ){
this.API = searchWin(window.opener);
}
if(this.API == null) {
this.API = wlc.nullAPI;
}
};
I need to be absolutely sure that the 2nd statement in LMSInitialize won't execute until getAPI finishes executing.
There's no way that could happen, right?