HTML and CSS Reference
In-Depth Information
Specifies a function to call when an error occurs in the worker thread. The onerror
method receives event data, including the following:
message : textual message of the error
filename : the filename the error occurred in
lineno : the line number in the file that created the error
As soon as the Worker object is instantiated, it's available for use at any time. All that's
needed to start the process is to call the postMessage method:
As soon as the webWorker is running, the main application continues as usual. If something
occurs that the worker process should be canceled, a call to the terminate method would
achieve this:
After the worker process completes and results need to be processed, the onmessage
function is called from the worker. This should be set up before starting the worker:
webWorker.onmessage = function(evt) {…}
That's everything required on the calling side or in the web application to create and
manage a worker process. Next, you need to create the worker code itself. For this, you create
the workercode.js file that was used in the constructor. The first line of the file will be the
onmessage property being assigned a function to process:
onmessage = function(e){…}
This tells the runtime the entry point to the work to be run within the worker process.
Somewhere in the worker process, where a result should be sent back to the calling applica-
tion, the postMessage method is called:
onmessage = function(e){
That's what's involved in creating a worker process. In the last piece, notice the user of the
self keyword. The self keyword is similar to the this keyword. The worker process runs in its
own context, meaning that it has its own global namespace. The self keyword gives access to
the global namespace within the worker process.
Search WWH ::

Custom Search