#

API Docs for: 0.9.4
Show: Inherited Protected Private Deprecated

# Task Class

Extends Object
Defined in: `../monkeybars.js:267`

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`

)

Defined in `../monkeybars.js:267`

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

- Index
- Methods
- Properties

## Item Index

### Methods

- cancel
- complete
- fault
- onCancel
- onChange
- onComplete
- onFault
- onStart
- performTask
- start

### Properties

- currentIndex
- displayName
- logLevel
- state
- timeout
- type

## Methods

### `cancel`

()

Defined in `../monkeybars.js:391`

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`

()

Defined in `../monkeybars.js:428`

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

#### Example:

            var task = new MonkeyBars.Task({
                performTask:function(){
                    this.complete();
                }
            });

            task.start();

### `fault`

(

- `error`

)

Defined in `../monkeybars.js:463`

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

### `onCancel`

()

Defined in `../monkeybars.js:565`

Convenience method called when the task is canceled.

### `onChange`

(

- `state`
- `error`

)

Defined in `../monkeybars.js:502`

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

#### Example:

            var task = new MonkeyBars.Task({
                performTask:function(){
                    this.complete();
                },
                onChange:function(state,error){
                    if(state == MonkeyBars.TaskStates.Completed){
                        alert("complete");
                    }
                }
            });

            task.start();

### `onComplete`

()

Defined in `../monkeybars.js:554`

Convenience method called when the task completes.

### `onFault`

(

- `error`

)

Defined in `../monkeybars.js:542`

Convenience method called when the task faults.

#### Parameters:

- `error` String

  Message describing error

### `onStart`

()

Defined in `../monkeybars.js:531`

Convenience method called when the task starts.

### `performTask`

()

Defined in `../monkeybars.js:576`

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

### `start`

()

Defined in `../monkeybars.js:604`

Kicks off the execution of the task by calling the tasks `performTask` method. This method can only be run once on a task.

## Properties

### `currentIndex`

Integer

Defined in `../monkeybars.js:667`

The index of the subtasks that have completed execution.

Default: 0

### `displayName`

String

Defined in `../monkeybars.js:331`

Display name for task. Used in logging output.

### `logLevel`

Integer

Defined in `../monkeybars.js:365`

The default logging level for tasks

Default: 0

### `state`

Integer

Defined in `../monkeybars.js:351`

The current state of the task

Default: 0

### `timeout`

Integer

Defined in `../monkeybars.js:378`

Time in milliseconds in which a task will time out and throw a fault

Default: undefined

### `type`

String

Defined in `../monkeybars.js:317`

The kind of task