Reputation: 51104
I have the following prototype code to trigger a process when a button is clicked:
jQuery("#queue-process").click(function() {
jQuery("#queue-process").attr("disabled", "disabled");
try {
processQueue();
} catch (e) {
console.log(e.message);
} finally {
jQuery("#queue-process").removeAttr("disabled");
}
});
The processQueue
function is always called, but the attr("disabled", "disabled")
is called only when I debug the anonymous function in the Chrome JavaScript console, i.e. if I place a breakpoint on that line, and single-step over it, it works, but outside of the debugger only processQueue()
executes.
Why could this be happening?
Upvotes: 2
Views: 148
Reputation: 2701
It's probably executing when you're not debugging too.
My guess is that processQueue() returns immediately, so the code goes to the finally block right away, and the component is re-enabled right away, so you don't actually see it. If you debug, you block execution, and you can see the component being disabled.
What is processQueue doing exactly? If it's doing some Ajax work, keep in mind that by default Ajax request are executed asynchronically. Maybe you need to pass a callback function to processQueue, so you only re-enable the #queue-process on completion of the work?
Upvotes: 5