ParallelTask Class
A ParallelTask is a TaskGroup that runs all of its subtasks ansynchronously. Its complete functionality is run when all of its sub tasks are complete.
Constructor
ParallelTask
-
attributes
Parameters:
-
attributesObjectList of attributes to apply to the task group
Example:
var parallel = new MonkeyBars.ParallelTask({
name:"ParallelTask",
tasks:[new MonkeyBars.Task({
performTask:function(){
this.complete();
}
})],
onComplete:function(){
alert(this.name + " is complete!");
}
});
parallel.start();
Item Index
Methods
- __onStateChange
- addSubTask
- addSubTaskAfterTask
- addSubTaskBeforeTask
- cancel
- canProcessSubTask
- complete
- destroy
- fault
- getTaskByName
- getTaskByTid
- has
- hasNoEnabledSubTasks
- initialize
- off
- on
- onCancel
- onComplete
- onFault
- onStart
- onSubTaskCancel
- onSubTaskComplete
- onSubTaskFault
- operate
- performTask
- processSubTask
- processSubTasks
- removeSubTask
- reset
- setDependeciesForTask
- start
- state
- trigger
Methods
__onStateChange
-
state -
error
This method is called during the execution lifecycle of the task. It is intentionally left blank and is up to the instance to describe it functionality.
Parameters:
-
stateIntegerThe current state of the task
-
errorStringMessage describing error
addSubTask
-
task
This method is overridden from TaskGroups implementation because of the
nature of a parallel task. When a task is added it should be immediately
processed and started.
Parameters:
-
taskObjectEither an object containing attributes of a task or
addSubTaskAfterTask
-
task -
afterTask
Adds a subtask after another task
Parameters:
-
taskObjectEither an object containing attributes of a task or
-
afterTaskObjectReference to an already added task
Example:
var parallel = new MonkeyBars.ParallelTask({
tasks:[task1,task3]
});
var task2 = new MonkeyBars.Task();
parallel.addTaskAfterTask(task2,task1);
addSubTaskBeforeTask
-
task -
beforeTask
Very similar to addSubTaskAfterTask except the inject task appears
before the second arguments position.
Parameters:
-
taskObjectEither an object containing attributes of a task or
-
beforeTaskObjectReference to an already added task
cancel
()
Cancel the group and cancel all of its subtasks
canProcessSubTask
()
Boolean
Returns:
complete
-
data -
operation
Calling this method says that the tasks execution is now complete.
Parameters:
-
dataObject -
operationString
Example:
var task = new MonkeyBars.Task({
performTask:function(){
this.complete();
}
});
task.start();
destroy
()
fault
-
error
Calling this method to fault a task. If it is part of a group task this will also call the groups fault method passing the error up to the group.
Parameters:
-
errorStringMessage associated with the cause of the fault.
Example:
var task = new MonkeyBars.Task({
performTask:function(){
var a = "a";
if(a != "b") {
this.fault("a != b");
}
}
});
task.start();
getTaskByName
-
name
Return a Task object, if it exists, based on the name passed.
Parameters:
-
nameStringThe user defined name
Returns:
getTaskByTid
-
tid
Return a Task object, if it exists, based on the tid passed.
Parameters:
-
tidStringThe id of the task you want
Returns:
Example:
var parallel = new MonkeyBars.ParallelTask({
tasks:[task1,task3]
});
parallel.getTaskByTid(task1.tid);
has
-
type
Checks to see if an event is registered to this object with the passed type.
Parameters:
-
typeString
Returns:
hasNoEnabledSubTasks
()
Boolean
Checks whether or not the group has any enabled sub tasks.
Returns:
initialize
-
attributes
Initialization functionality
Parameters:
-
attributesObject
off
-
type -
callback
Removes an event to the object.
Parameters:
-
typeString -
callbackFunction
on
-
type -
callback -
context -
configurable
Attaches an event to the object.
Parameters:
-
typeString -
callbackFunction -
contextObject -
configurableBooleanWhether or not you should be able to remove this listener without passing its callback reference
onCancel
()
Convenience method called when the task is canceled.
onComplete
()
Convenience method called when the task completes.
onFault
-
error
Convenience method called when the task faults.
Parameters:
-
errorStringMessage describing error
onStart
()
Convenience method called when the task starts.
onSubTaskCancel
-
task
Called when a subtask calls its cancel method. When a subtask is canceled any other subtasks that are dependent on the canceled task are cancled.
Parameters:
-
taskTaskThe task that was just canceled
onSubTaskComplete
-
task
Overridden from TaskGroup. This method is run everytime a sub task completes. When all subtasks are complete the groups complete method is called.
Parameters:
-
taskTask
onSubTaskFault
-
error -
task
Called when a subtask calls its fault method.
Parameters:
-
errorStringError message.
-
taskTaskThe task that just completed
performTask
()
Overridden from Task. First checks to see if there are any enabled subtasks to process. If there arent the groups complete method is called. If there are then the group processes all of the sub tasks it has.
processSubTask
-
task
Overridden from TaskGroup. Processes a sub task and prepares it for execution. This method overwrites the tasks on change functionality. If you wish to have a sub task that handles its own change functionality then you will need to implement the partner convenience methods.
Parameters:
-
taskTaskSubtask to process
processSubTasks
()
Processes all of the sub tasks available for the group
removeSubTask
-
task
Removes a task from its group. Removing the task after it has executed will have no apparent affect as it has already ran.
Parameters:
-
taskTaskThe task you wish to remove from the group.
reset
()
Resets a task to its original state
start
()
Kicks off the execution of the task by calling the tasks performTask method.
This method can only be run once on a task.
state
()
Integer
Getter for the tasks current state. Code outside of an implementation should not set the state as this is an internal property.
Returns:
trigger
-
type
Triggers the firing of an event on an object.
Parameters:
-
typeString
Properties
_currentIndex
Integer
private
The index of the subtasks that have completed execution.
_dependencyMap
Object
private
Holds all references to event types, callbacks, contexts and configurations.
_eventMap
Object
private
Holds all references to event types, callbacks, contexts and configurations.
_processedIndex
Integer
private
An incrimented number of the tasks that have already been processed.
_state
Integer
private
The current state of the task
concurrent
Boolean
Whether or not to run the task concurrently through Web Workers
Default: false
displayName
String
Display name for task. Used in logging output.
logLevel
Integer
The default logging level for tasks
Default: 0
timeout
Integer
Time in milliseconds in which a task will time out and throw a fault
Default: undefined
type
String
The kind of task
worker
Object
This object can either be simply a reference to a custom WorkerTask extention's
constructor. Or it can be an object with a constructor key/value pair. If it is the
latter then you also have the option of passing a handler function that will be run
on the onMessage handler of the Worker itself.
Default: undefined
Example:
var task = new MonkeyBars.Task({
...
worker:{
constructor:CustomWorker,
handler:function(e){
// called when a postMessage is posted from the task
}
},
...
});
var task = new MonkeyBars.Task({
...
worker:CustomWorker,
...
});
