Tutorial :How to get parallel behavior in Java Script?



Question:

More or less I want to execute two functions in parallel. One way as I see is doing through SetTimeOut function.

I have not completely gone through the ReactiveExentension, although it looks promising but may be overkill for my needs.

Is there any framework which supports parallelism ?

My use case is trivial, but I would like to know if anybody heavily needed parallelism in Java Script ?

Thanks, Biswanath.


Solution:1

You're not going to manage to put your program into a new thread unless the browser lets you do it and the only way that I can see that being plausible (assuming the browser doesn't provide some specific JavaScript extensions) is if it creates a new thread/process for each frame.

That said, you could likely have two scripts run alongside each other, simultaneously, by putting them into different frames, or iframes. Simply create multiple, invisible iframes on your web page and into each load a HTML document with your own JavaScript functions. Of couse you're not going to be able to tell the any of these pages to start processing something, but you could have them poll the top window for something to do then do their thing and then tell the top window when it's finished.

Just an idea.


Solution:2

You could read this article here, it talks about threading : http://blog.monstuff.com/archives/000315.html


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »