Reputation:
I read in Windows 8 development tutorial that Metro apps written using HTML/JavaScript runs on single thread. If so, how it executes asynchronous functions in WinRT?
Upvotes: 0
Views: 416
Reputation: 30152
It's a multi part answer.
Traditionally - yes it is single threaded. Async is done behind the scenes with timers. However with the advent of web workers, you can run background processing on multiple threads (or use a Windows Runtime component that does threading and relies on .NET for the threading here).
Web Workers are supported in Windows Store HTMl/JS applications so yes, you can have more than one thread.
Upvotes: 2
Reputation: 7211
Yes, the JavaScript engine is indeed single-threaded. Calls to the API are all native code though and as such can - and mostly do - open separate threads.
See this MSDN article for a thorough explanation of the underlying mechanics as well as some recommendations on how to deal with this in your code.
The WinJS Promise internally also uses setImmediate
to allow the rendering and message loop to take over between multiple JavaScript functions and - as an important side-effect - shorten the callstack.
Upvotes: 0