I'm building a multi-threaded client side javascript application, and I would like to have a background thread pull binary data and pass it to the main thread. I know this can be done in other languages via serialization, but how do I accomplish this in javascript?
Are you open to using Google Gears? This is exactly the kind of thing their WorkerPool threading implementation is for.
I might turn this application into a standalone XULrunner application down the line for even more efficiency, so I'd rather go the HTML5 "web workers" route versus using Gears.
The Web Workers postMessage API takes a JavaScript object. The Mozilla Using web workers documentations says:
You can safely pass objects in and out of workers using the postMessage() method; objects are automatically converted to JSON internally.
So, you can use any JavaScript object that supports or can be converted to your binary data. Depending on other factors, maybe convert to a Base64 string (see How can you encode to Base64 using Javascript?) or use an array on numbers.
I just wrote a blog post about this crippling feature: http://www.picnet.com.au/blogs/Guido/post/2010/02/18/Html-Web-Worker-Woes-Data-Analysis-not-an-Option.aspx
You may find it interesting.
Thanks
Guido