Is it possible to call multiple functions at the same time?
E.g.
var executed = false;
// loop 1
func();
// loop 2
func();
function func(){
if (executed) return;
executed = true;
alert(1);
}
Can func() be executed 2 times at once?
JavaScript has no native support for running multiple functions simultaneously. It has, historically, depended on time-consuming tasks (such as waiting for an HTTP request or doing something CPU intensive) being handled with native code that presents an API to JS (and that API accepting a callback or, more recently, returning a Promise).
That is starting to change.
Most web browsers support Web Workers and Node.js has introduced experimental support for Worker Threads.
These each allow JavaScript code to be farmed off to a separate process which runs independently of the main event loop and communicate with the main process using messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With