I am dynamically loading code (functions) from a server and executing it as javascript code then storing it in an array and executing. All these snippets of code must be executed exactly once. The psuedocode follows as such
function fetch(foo){
if (foo in fooArray){
//Do Nothing
else{
//Fetch foo via Ajax and execute foo()
}
}
The problem is vastly more complex, but essentially if I issue the below command
fetch('someFunctionName');
fetch('someFunctionName');
fetch('someFunctionName');
fetch('someFunctionName');
all four will execute the if (foo in fooArray)
and assume that it is not in the array, and all four will proceed to fetch the code and execute it. I remember back in the day learning about semaphores and mutexes, are there such things for javascript.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…