WorkerTask Class
Creates a new worker representation of the task
Constructor
WorkerTask
-
task
Parameters:
-
taskTaskThe 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
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
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:
-
protoPropsObject
Returns:
fault
-
error
Posts a fault message to the main thread that the task has faulted. Passes an error as its value.
Parameters:
-
errorObject
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:
-
typeString -
valueObject
