API Docs for: 0.9.14
Show:

Task Class

Uses
Extends Object

The simplest form of a MonkeyBars task. Once started the task executes all functionality located within the performTask function block. Set logLevel to see console logs during task execution.

Constructor

Task

(
  • attributes
)

Parameters:

  • attributes Object

    List of attributes to apply to the task

Example:

var task = new MonkeyBars.Task({
    name:"ExampleTask",
    performTask:function(){
        this.complete();
    },
    onComplete:function(){
        alert(this.name + " is complete!");
    }
});
task.start();

Methods

__onStateChange

(
  • state
  • error
)
private

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:

  • state Integer

    The current state of the task

  • error String

    Message describing error

cancel

()

Calling this method cancels the task. However it is up to the instance to handle the canceled state.

Example:

var task = new MonkeyBars.Task({
    performTask:function(){
        if(true){
            this.cancel();
        }
    }
});
task.start();

complete

(
  • data
  • operation
)

Calling this method says that the tasks execution is now complete.

Parameters:

  • data Object
  • operation String

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:

  • error String

    Message 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();

has

(
  • type
)
Boolean

Checks to see if an event is registered to this object with the passed type.

Parameters:

  • type String

Returns:

Boolean: Whether or not the object contains the listener type

initialize

(
  • attributes
)

Initialization functionality

Parameters:

  • attributes Object

off

(
  • type
  • callback
)

Removes an event to the object.

Parameters:

  • type String
  • callback Function

on

(
  • type
  • callback
  • context
  • configurable
)

Attaches an event to the object.

Parameters:

  • type String
  • callback Function
  • context Object
  • configurable Boolean

    Whether 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:

  • error String

    Message describing error

onStart

()

Convenience method called when the task starts.

operate

(
  • data
  • task
)

Parameters:

  • data Object
  • task Task

performTask

()

This method is required for simple tasks and will throw an exception if it is called and not overridden. If you overwrite this method on a task group then you need to make sure that you call the extended/implemented classes original prototype method (see the example below).

Example:

var parallel = new MonkeyBars.ParallelTask({
    ...
    performTask:function(){
        // custom functionality
        MonkeyBars.ParallelTask.prototype.performTask.call(this);
    }
    ...
})

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:

Integer: The current state of the task

trigger

(
  • type
)

Triggers the firing of an event on an object.

Parameters:

  • type String

Properties

_eventMap

Object private

Holds all references to event types, callbacks, contexts and configurations.

_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,
    ...
});