I have had a big problem with race conditions in ActionFunctions corrupting my viewstate.
When I call an AF to update one thing, and then click a button to do another, if the second finishes first, and then the actionfunction completes, ViewState gets reset to the result of the actionfunction.
This is a pretty straightforward symptom of ViewState. It is also a problem when a component calls one function, and then the page calls another, since both modify the entire viewstate.
I attempted to solve this by creating a window level function runAf(actionfunction), and in the oncomplete of every actionfunction call afComplete();
function afComplete(event){
if (window.AF_Queue.length == 0) {
window.RunningAF = false;
} else {
var fn = window.AF_Queue.shift();
fn();
}
return false;
}
function runAf(af) {
if (!window.RunningAF) {
window.RunningAF = true;
af();
} else {
window.AF_Queue.push(af);
}
}
Both the page and controller use this to run their action functions. Unfortunately, nothing happens, and the actionfunctions fail to execute entirely.
I am at wits end on this, and don't want to re-write something that works perfectly, just because clicking buttons too fast causes it to break.
I considered moving to Remote Functions, but I don't trust that they will work used this way based on my experience with actionfunctions.
Any insight?