As I know, JavaScript is single-threaded. Only a few functions can run in async mode such as setTimeout, setInterval, XHR, ... etc. Also all the event callback will be run in async mode. Is there any other JavaScript function can run in async mode?
Asked
Active
Viewed 309 times
-4
-
In which version of Javascript, and on what browser / in what engine? – S McCrohan Apr 27 '15 at 02:22
-
I want to ask a question that which functions in javascript will be ran in async mode. – Will Huang Apr 30 '15 at 18:29
1 Answers
2
There is the HTML5 web worker API, which allows you to a run parallel threads in JavaScript.

Deni Spasovski
- 4,004
- 3
- 35
- 52
-
There is also File API's FileReader https://developer.mozilla.org/en-US/docs/Web/API/FileReader and all event listeners can bee seen as async. – Wio Apr 27 '15 at 02:26
-
@Deni: You changed my title and body of my question which is not what I want to ask. I changed a little bit. Hope you can understand. – Will Huang Apr 30 '15 at 18:45
-
as I know, setTimeout and setInterval will let my callback function run into a async manner. I just want to know is any others way to run callback function in async way. – Will Huang Apr 30 '15 at 18:47
-
JavaScript is async and single threaded, additionally there is a HTML5 api which allows you to use multiple threads. Every event that occurs on a web page is async. Can you share more details about your use case ? – Deni Spasovski Apr 30 '15 at 18:59
-
I think this post answered part of my question: http://stackoverflow.com/questions/2035645/when-is-javascript-synchronous Quote: "Javascript is always synchronous and single-threaded" – Will Huang May 01 '15 at 17:30
-
1yep, that's true, additionally if you want true multi thread environment for background calculations you can use the web worker api – Deni Spasovski May 01 '15 at 20:01