HTML and CSS Reference
In-Depth Information
FIGURE 10.2 Everything you
could ever need: prime number
and drawing executed without
interruption thanks to Web
Matryoshka dolls: workers inside workers
If you had a watchful eye, you would have spotted that from
within a worker you can also create new workers. Currently only
Firefox supports this, but it's part of the spec, so you should
expect that other browsers will update to include this feature.
What this means is that you could spawn one worker, who
then goes and splits its job into lots of delegated little jobs and
passes them to sub-workers. Let's go back to the example of
applying a complex fi lter to a photo in your super-sexy online
image web app. To speed up the processing of the image—and
if it made sense in the fi lter—you could split the image up into
regions and pass each region of image data to a sub-worker.
As each worker returns, you reduce the pending count and
once all the workers have fi nished, the main worker returns the
fi n a fi p r o c e s s e d fi m a g e d a t a t o t h e p a r e n t d o c u m e n t . S o m e t h fi n g
like this (I've left out some functions from the listing as this is
just to demonstrate the idea):
var pendingWorkers = 0,
results = {},
workingWidth = 100;
onmessage = function (event) {
Search WWH ::

Custom Search