#

API Docs for: 0.9.8
Show: Inherited Protected Private Deprecated

# ParallelTask Class

Extends TaskGroup
Defined in: `../monkeybars.js:1399`

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`

)

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

#### Parameters:

- `attributes` Object

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

- Index
- Methods
- Properties

## Item Index

### Methods

- addSubTask
- addSubTaskAfterTask
- addSubTaskBeforeTask
- cancel
- complete
- fault
- getTaskById
- getTaskByName
- getTaskByTid
- handleProduct
- hasNoEnabledSubTasks
- onCancel
- onChange
- onComplete
- onFault
- onStart
- onSubTaskCancel
- onSubTaskComplete
- onSubTaskFault
- performTask
- processSubTask
- processSubTasks
- removeSubTask
- start

### Properties

- concurrent
- currentIndex
- displayName
- logLevel
- max
- processedIndex
- product
- state
- timeout
- type
- worker

## Methods

### `addSubTask`

(

- `task`

)

Inherited from TaskGroup but overwritten in `../monkeybars.js:1535`

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:

- `task` Object

  Either an object containing attributes of a task or

### `addSubTaskAfterTask`

(

- `task`
- `afterTask`

)

Inherited from TaskGroup: `../monkeybars.js:1097`

description

#### Parameters:

- `task` Object

  Either an object containing attributes of a task or

- `afterTask` Object

  Reference 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`

)

Inherited from TaskGroup: `../monkeybars.js:1132`

Very similar to `addSubTaskAfterTask` except the inject task appears before the second arguments position.

#### Parameters:

- `task` Object

  Either an object containing attributes of a task or

- `beforeTask` Object

  Reference to an already added task

### `cancel`

()

Inherited from Task but overwritten in `../monkeybars.js:1346`

Cancel the group and cancel all of its subtasks

### `complete`

()

Inherited from Task: `../monkeybars.js:783`

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`

)

Inherited from Task: `../monkeybars.js:819`

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

### `getTaskById`

(

- `id`

)

Inherited from TaskGroup: `../monkeybars.js:1308`

Return a Task object, if it exists, based on the `id` passed.

#### Parameters:

- `id` String

  The user defined id

### `getTaskByName`

(

- `name`

)

Inherited from TaskGroup: `../monkeybars.js:1327`

Return a Task object, if it exists, based on the `name` passed.

#### Parameters:

- `name` String

  The user defined name

### `getTaskByTid`

(

- `tid`

)

Inherited from TaskGroup: `../monkeybars.js:1281`

Return a Task object, if it exists, based on the `tid` passed.

#### Parameters:

- `tid` String

  The id of the task you want

#### Example:

            var parallel = new MonkeyBars.ParallelTask({
                tasks:[task1,task3]
            });

            parallel.getTaskByTid(task1.tid);

### `handleProduct`

()

Inherited from TaskGroup: `../monkeybars.js:611`

description

### `hasNoEnabledSubTasks`

() Boolean

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

Checks whether or not the group has any enabled sub tasks.

#### Returns:

Boolean: Has sub tasks or not

### `onCancel`

()

Inherited from Task: `../monkeybars.js:921`

Convenience method called when the task is canceled.

### `onChange`

(

- `state`
- `error`

)

Inherited from Task: `../monkeybars.js:858`

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`

()

Inherited from Task: `../monkeybars.js:910`

Convenience method called when the task completes.

### `onFault`

(

- `error`

)

Inherited from Task: `../monkeybars.js:898`

Convenience method called when the task faults.

#### Parameters:

- `error` String

  Message describing error

### `onStart`

()

Inherited from Task: `../monkeybars.js:887`

Convenience method called when the task starts.

### `onSubTaskCancel`

(

- `task`

)

Inherited from TaskGroup: `../monkeybars.js:1192`

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:

- `task` Task

  The task that was just canceled

### `onSubTaskComplete`

(

- `task`
- `product`

)

Inherited from TaskGroup but overwritten in `../monkeybars.js:1559`

Overridden from TaskGroup. This method is run everytime a sub task completes. When all subtasks are complete the groups complete method is called.

#### Parameters:

- `task` Task
- `product` Object

### `onSubTaskFault`

(

- `error`
- `task`

)

Inherited from TaskGroup: `../monkeybars.js:1177`

Called when a subtask calls its fault method.

#### Parameters:

- `error` String

  Error message.

- `task` Task

  The task that just completed

### `performTask`

()

Inherited from Task but overwritten in `../monkeybars.js:1582`

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`

)

Inherited from TaskGroup but overwritten in `../monkeybars.js:1480`

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:

- `task` Task

  Subtask to process

### `processSubTasks`

()

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

Processes all of the sub tasks available for the group

### `removeSubTask`

(

- `task`

)

Inherited from TaskGroup: `../monkeybars.js:1262`

Removes a task from its group. Removing the task after it has executed will have no apparent affect as it has already ran.

#### Parameters:

- `task` Task

  The task you wish to remove from the group.

### `start`

()

Inherited from Task: `../monkeybars.js:960`

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

## Properties

### `concurrent`

Boolean

Inherited from Task: `../monkeybars.js:638`

Whether or not to run the task concurrently through Web Workers

Default: false

### `currentIndex`

Integer

Inherited from Task: `../monkeybars.js:1028`

The index of the subtasks that have completed execution.

Default: 0

### `displayName`

String

Inherited from Task: `../monkeybars.js:686`

Display name for task. Used in logging output.

### `logLevel`

Integer

Inherited from Task: `../monkeybars.js:720`

The default logging level for tasks

Default: 0

### `max`

Integer

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

The max amounts of tasks that can run simultaneously

### `processedIndex`

Integer

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

An incrimented number of the tasks that have already been processed.

### `product`

Object

Inherited from Task: `../monkeybars.js:598`

Task product

Default: undefined

### `state`

Integer

Inherited from Task: `../monkeybars.js:706`

The current state of the task

Default: 0

### `timeout`

Integer

Inherited from Task: `../monkeybars.js:733`

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

Default: undefined

### `type`

String

Inherited from Task but overwritten in `../monkeybars.js:1431`

The kind of task

### `worker`

Object

Inherited from Task: `../monkeybars.js:651`

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