I have an <apex:actionFunction>
which can take a long while to complete. While the action function is executing, I would like to be able to execute some on page JavaScript to make the users waiting experience more interesting (Changing onscreen messages etc)
- Call action function.
- Run on page JavaScript.
- When action function completes, stop on page JavaScript and run oncomplete code.
However, it seems that JavaScript is single threaded. Is there any way round this?
Thanks
Best Answer
A single event function is single-threaded in nature, and JavaScript itself generally behaves as if it were single-threaded (but WebWorkers provide multiple threads, and event handlers can execute in apparently multiple threads, as per a discussion on SE).
The best way to ensure a concurrent effect is to use
setTimeout
orsetInterval
on the animation function, thus allowing the browser to execute the animation periodically while processing occurs.A demonstration of this animation procedure follows: