Javascript Web Workers: Opera 10.6 Beta Supports SharedWorkers


While poking around the Web Worker API in the latest Opera Beta Release, I discovered that they had also implemented support for Shared Web Workers. If you’re not familiar with Shared Web Workers, have a look here. The basic premise is that a Shared Worker can have multiple connections made to one Worker.


Paraphrased from the specification for clarity:


[Instead of a single message processing function, workers can attach multiple event listeners, each one performing a quick check to see if it is relevant for the message. If multiple authors wanted to collaborate using a single port to communicate with a worker, it would allow for independent code instead of changes having to all be made to a single event handling function.]

So how about some code? In order to run the demo I’ve prepared, you’ll need Opera 10.6 Beta 1. Then hop over to Github and grab the Gist.


The comments will guide you through each step of the demo’s functionality.


Basic HTML page for running the test:

The HTML page called in the iframe:

The Renderer (that’s your browser window)

The SharedWorker


This demonstrates how we can connect two different pages to the same SharedWorker process, and track our connections to them from one persistent object variable. Very exciting!

Edit In the time since this was originally published, Chrome, Safari & Opera now support complex JSON messages.

This entry was posted by Rick Waldron (@rwaldron) on June 18, 2010 in JavaScript, Opera and Web Workers.

Comments

Author

This entry was posted by Rick Waldron (@rwaldron) on June 18, 2010 in JavaScript, Opera and Web Workers.

Recent posts from this author

Related on the Bocoup Blog

Advertisement

Twitter

Google+