Pot.js - Pot.Workeroid Example

Pot.Workeroid is a constructor that is compatible and flexible with HTML5 WebWorkers API, and it emulates to work cross-browser if environment is not supported native Worker.

That will used the Worker on web browser, and will use the ChromeWorker if script runs on userscript(Greasemonkey) or on XUL (Firefox add-ons). If environment cannot use both will runs in the background simply.

Either case, you can exit the worker thread by "terminate" method.

You can use the postMessage, terminate, onerror, onmessage, and add/removeEventListener APIs like native Worker.

In addition, Pot object is available from the Worker thread. You can use Pot.js library if Pot.js is running, and can use PotLite.js library if PotLite.js is running. Therefore, you can execute worker without burdening the CPU by Pot.js asynchronous iterators (e.g. Pot.Deferred.forEach).

Pot.Workeroid is possible to pass Function object in addition to a filename to constructor.

This example code is simply an search for a prime number.

The postMessage() method is used to send a message back to the parent thread when a prime is found.

You can terminate process by clicking "Stop" button.