User:Jeblad/Javascript and Mediawiki/Worker

A Worker or WebWorker is a separate and limited executing environment set up so it is possible to pass messages back and fort between the world executable (often the browser) and the separate worker environment. The separation creates a simple and safe means to execute lengthy processing without locking up the main UI thread. The child itself is often implemented as a separate OS process. There is no shared objects between the world and the children, or between any child and subchildren, and there is no synchronization involved.


 * Object in Wikipedia
 * Object in MDN

--
 * World executable : This is typically from the page. The uri variable holds a complete link to the script page that constructs the worker process. After constructing the worker process an onmessage handler and an onerror handler is set up, and after that a message is posted to the worker. This message is although only delivered when the worker process is ready to handle the message.


 * Child executable : This is typically from a page. As soon as the worker process is set up the onmessage handler becomes active and the posted message from the world process will be handled. It will then fire a new message back to the world with a small addition. Uncommenting the last line in the onmessage call will generate an error which is reported to the onerror handler in the world executable.