Wednesday, October 14, 2009

Threading in JavaScript with Web Workers

One of the things that I love about lower-level programming languages like C/C++, and even Java, are the fact that you can thread off new processes in the background. Since a lot of my work involves creating web applications, I work with JavaScript a lot. It really got to me that everything is single-threaded. I'm embarrassed to say that I haven't really read much on Web Workers until recently, but once I learn about something as great as this, I must make it my own! I scoured the web for examples and specs, until I had my fill. While the implementation is great for the web, and will bring about even better applications, I did not like the interface that it was presented in.

I always loved the simplicity of Java Threads, so I felt inclined to create a decorator for Web Workers that would give it a Java Thread interface. This will consist of a Thread object that  runs an object of type Runnable, in the background.

UPDATE: The cross-browser implementation is finished! Go ahead and knock yourselves out.

You can check out the work in progress here;

JSRun

The implementation seems simple enough to me, but I'm curious as to what others might think.

No comments:

Post a Comment