#

API Docs for: 0.9.8
Show: Inherited Protected Private Deprecated

# WorkerTask Class

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

Creates a new worker representation of the task

## Constructor

### `WorkerTask`

(

- `task`

)

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

#### Parameters:

- `task` Task

  The task we're creating this worker representation from

#### Example:

        var CustomWorker = MonkeyBars.WorkerTask.extend({
            append:function(product){
                this.postMessage("append",100);
            },
            devide:function(product){
                this.postMessage("devide",2);
                this.complete(product/2);
            }
        });

        var task = new MonkeyBars.Task({
            ...
            concurrent:true,
            worker:{
                constructor:CustomWorker,
                handler:function(e){
                    if(e.data.type === "append") {
                        ...
                    } else if(e.data.type === "devide") {
                        ...
                    }
                }
            }
            ...
        });

        task.start();

- Index
- Methods

## Item Index

### Methods

- cancel
- complete
- fault
- postMessage

## Methods

### `cancel`

()

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

Posts a cancel message to the main thread that the task has been canceled.

### `complete`

()

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

Post a complete message along with the product passed stating that the task has completed what it needs to.

### `fault`

(

- `error`

)

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

Posts a fault message to the main thread that the task has faulted. Passes an error as its value.

#### Parameters:

- `error` Object

### `postMessage`

(

- `type`
- `value`

)

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

Convenience method for posting messages to the main thread. You should opt into using this as it is how the rest of the WorkerTask core methods communicate with the main thread.

#### Parameters:

- `type` String
- `value` Object