-
Notifications
You must be signed in to change notification settings - Fork 0
Task Implementation
Eric McGary edited this page Jan 5, 2013
·
3 revisions
### Simple Task
Monkeybars.Task is the simplest form of a task possible. You can override any of the methods provided (granted you must then call the prototype version of the method), but in its simplest form a task only requires the performTask method to be present. For a list of all possible methods and properties available have a look at the documentation.
var task = new MonkeyBars.Task({
name:"SimpleTask",
loggingEnabled:true,
onChange:function(state,error){
if(state == MonkeyBars.TaskStates.Completed) {
alert("The 'SimpleTask' is complete");
}
},
performTask:function(){
this.complete();
}
});
task.start();
Task groups are a great way to contain and structure both serial and async units of code. There are numerous syntax variations that you can use in order to create and add subtasks to a task group. Have a look at the group, parallel and sequence specs within the tests directory for all of the possible variations.
var group = new MonkeyBars.SequenceTask({
name:"SimpleTask",
loggingEnabled:true,
tasks:[{
name:"subtask1",
performTask:function(){
// run task functionality
this.complete();
}
},
{
name:"subtask2",
performTask:function(){
// run task functionality
this.complete();
}
}]
});
group.start();