Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I 'fire and forget' a JS function? (do not wait for return)

Tags:

javascript

I want to set a JS function running, but not wait for the response. The only way I can think to do it is:

setTimeout(function() {
    myFunc(); 
},0);

But that seems... inefficient at best. Any ideas?

like image 908
Alastair Avatar asked Jan 19 '12 13:01

Alastair


2 Answers

You might want to look at webworkers

like image 193
qwertymk Avatar answered Oct 23 '22 03:10

qwertymk


Why is that inefficient?

Also, don't forget that browser javascript is single-threaded. So, while your function runs, you will implicitly wait for it to return.

(async ajax calls may be an exception here)

like image 33
Sergio Tulentsev Avatar answered Oct 23 '22 01:10

Sergio Tulentsev