API Docs for: 0.9.14
Show:

WorkerTask Class

Extends Object

Creates a new worker representation of the task

Constructor

WorkerTask

(
  • task
)

Parameters:

  • task Task

    The task we're creating this worker representation from

Example:

var CustomWorker = MonkeyBars.WorkerTask.extend({
    append:function(data){
        this.postMessage("append",100);
    },
    devide:function(data){
        this.postMessage("devide",2);
        this.complete(data/2);
    }
});
var task = new MonkeyBars.Task({
    ...
    concurrent:true,
    worker:{
        constructor:CustomWorker,
        handler:function(e){
            if(e.data.type === "append") {
                ...
            } else if(e.data.type === "devide") {
                ...
            }
        }
    }
    ...
});
task.start();

Item Index

Methods

cancel

()

Posts a cancel message to the main thread that the task has been canceled.

complete

()

Post a complete message along with the data passed stating that the task has completed what it needs to.

extend

(
  • protoProps
)
Function

Extention functionality for worker tasks. This is different than the core extend functionality because we need to make sure that all of the protoprops provided are available on the task because of its concurrent nature.

Parameters:

  • protoProps Object

Returns:

Function: child Constructor function for extended task type

fault

(
  • error
)

Posts a fault message to the main thread that the task has faulted. Passes an error as its value.

Parameters:

  • error Object

postMessage

(
  • type
  • value
)

Convenience method for posting messages to the main thread. You should opt into using this as it is how the rest of the WorkerTask core methods communicate with the main thread.

Parameters:

  • type String
  • value Object