API Documentation for: 1.1.23
Show:

Worker Class

Defined in: Worker:14
Namespace: cloudkid

The Web Workers specification defines an API for spawning background scripts in your web application. Web Workers allow you to do things like fire up long-running scripts to handle computationally intensive tasks, but without blocking the UI or other scripts to handle user interactions. Because Workers aren't available on all browsers, we provide a helpful polyfill for backward compatibility.

var workerCode = "this.initialVariable = 10;" +
"this.onmessage = function(event)" +
"{" +
    "var data = event.data;" +
    "var returnVal = this.initialVariable + data.addValue;" +
    "this.postMessage(returnVal);" +
"};";

// Create the worker
var worker = cloudkid.Worker.init(workerCode);
worker.onmessage = function(e) {
    // e.data is the returnVal
};

// Start the worker.
worker.postMessage();

Item Index

Methods

Methods

init

(
  • codeString
)
FallbackWorker | window.Worker static

Defined in init:42

Initialize the worker, this is how you create a Worker or FallbackWorker object.

Parameters:

  • codeString String

    The code in string form to make the worker from. As a string, fallback support is easier.

Returns:

FallbackWorker | window.Worker:

Either a Web Worker or a fallback with the same API to use.