Class Index | File Index

Classes


Class Pot.Workeroid


Defined in: <potlite.js>.

Class Summary
Constructor Attributes Constructor Name and Description
 
Pot.Workeroid(script)
Pot.Workeroid implements an API for running scripts in the background independently of any user interface scripts that is inherited from the native Worker.
Field Summary
Field Attributes Field Name and Description
 
A unique strings.
Method Summary
Method Attributes Method Name and Description
 
addEventListener(type, func)
Add an event.
 
isWorkeroid.
 
Post a message.
 
Remove an event.
 
Terminate process.
 
toString.
Class Detail
Pot.Workeroid(script)
Pot.Workeroid implements an API for running scripts in the background independently of any user interface scripts that is inherited from the native Worker. Pot.Workeroid emulates native Worker API if user environment not has Web Worker. This allows for background tasks for long-running scripts or heavy-weight processing that are not interrupted by scripts that respond to user interactions.
  var worker = new Pot.Workeroid(function(data) {
    // This function scope is a child Worker's "onmessage" that
    //  will be other process or thread.
    switch (data) {
      case 'foo':
          postMessage('foo!');
          break;
      case 'bar':
          postMessage('bar!');
          break;
      default:
          postMessage('hello!');
          break;
    }
  });
  // You can coding like same usage of native Worker.
  worker.onmessage = function(data) {
    Pot.debug(data);
  };
  worker.onerror = function(err) {
    Pot.debug(err);
  };
  // Sends data and starts Worker thread.
  worker.postMessage('foo');
  // -- results --
  //  This will be received a message "foo!" from a child Worker.
  //
Parameters:
{String|Function|Object|*} script
Script that will runs in child processing.
Returns:
{Pot.Workeroid} Returns an instance of Pot.Workeroid.
Field Detail
{String} serial
A unique strings.
Method Detail
{Function} addEventListener(type, func)
Add an event.
Parameters:
{String} type
Event type. ('message' or 'error').
{Function} func
Event callback function.
Returns:
{Pot.Workeroid} Returns an instance of Pot.Workeroid.

{Function} isWorkeroid()
isWorkeroid.

{Function} postMessage(data)
Post a message.
Parameters:
{String} data
Message.
Returns:
{Pot.Workeroid} Returns an instance of Pot.Workeroid.

{Function} removeEventListener(type)
Remove an event.
Parameters:
{String} type
Event type. ('message' or 'error').
Returns:
{Pot.Workeroid} Returns an instance of Pot.Workeroid.

{Function} terminate()
Terminate process.
Returns:
{Pot.Workeroid} Returns an instance of Pot.Workeroid.

{Function} toString()
toString.
Returns:
Return formatted string of object.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Sep 21 2012 19:35:45 GMT+0900 (JST)