HTML and CSS Reference
In-Depth Information
pool
.
init
();
var
workerTask
=
new
WorkerTask
(
workers
.
script
,
mycallback
,
slidfast
.
worker
.
obj
());
After initializing the worker threads, add the actual
workerTasks
to process the data:
pool
.
addWorkerTask
(
workerTask
);
slidfast
.
worker
.
obj
().
foo
=
10
;
pool
.
addWorkerTask
(
workerTask
);
slidfast
.
worker
.
obj
().
foo
=
20
;
pool
.
addWorkerTask
(
workerTask
);
slidfast
.
worker
.
obj
().
foo
=
30
;
pool
.
addWorkerTask
(
workerTask
);
As you can see in
Figure 9-2
, each thread brings data back to the main page and renders
it with the supplied callback. The thread order varies on each refresh and there is no
guarantee on how the browser will process the data. To see a demo, visit
http://
html5e.org/example/workers
.
Use the latest version of Chrome or another browser that
supports actual CPU core usage per web worker.
Figure 9-2. Data being returned by multiple Web Worker threads in parallel