I'm trying to create a simple loading animation for an arbitrary function in JQuery Terminal. I know that JavaScript is single threaded and synchronous, but are there any workarounds?
I've seen the JQuery progress bar animation example, but I'm not sure how I can run an animation similar to that while another function runs on the background. Could I potentially use async and await functions?
Below is a simple reproducible example:
var terminal = $('#terminal').terminal( function(command, term) {
arbitrary_function();
let i = 0;
let loading_animation = ['[LOADING ]', '[LOADING . ]', '[LOADING .. ]', '[LOADING ... ]', '[LOADING ....]']
(function loop() {
terminal.set_prompt(loading_animation[i]);
timer = setTimeout(loop, 550);
i = ((i + 1) % 5);
})();
}
Ideally, I'd want everything below arbitrary_function() to run until arbitrary_function() is done. How can I possibly do that in JavaScript?