GODPAPER | All Packages | All Classes | Index | Frames No Frames |
DelegateTask

Package | org.spicefactory.lib.task.util
Class | public class DelegateTask
Inheritance | DelegateTask Task flash.events.EventDispatcher

A Task implementation that delegates the actual execution of the operation. This may be useful if you want to integrate existing classes that cannot be retrofitted to be subclasses of `Task`, but need to act as children of a `TaskGroup`.

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | cancelable : Boolean [read-only] Indicates whether this Task can be cancelled. | Task
|  | data : * An arbitrary value associated with this Task. | Task
|  | parent : TaskGroup [read-only] The parent of this Task. | Task
|  | restartable : Boolean [read-only] Indicates whether this Task can be restarted. | Task
|  | root : Task [read-only] The root TaskGroup in case this Task is nested in one or more TaskGroups. | Task
|  | skippable : Boolean [read-only] Indicates whether this Task can be forced to skip to its final state. | Task
|  | state : TaskState [read-only] The current state of this Task. | Task
|  | suspendable : Boolean [read-only] Indicates whether this Task can be suspended. | Task
|  | timeout : uint [read-only] The timeout for this Task in milliseconds. | Task

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | DelegateTask(startFunction:Function, name:String = null, isRestartable:Boolean = true, timeout:uint = 0) Creates a new instance. | DelegateTask
|  | cancel():Boolean Cancels this Task. | Task
|  | markComplete():Boolean Signals that this Task has completed. | DelegateTask
|  | markError(message:String):Boolean Signals an error condition and cancels the Task. | DelegateTask
|  | resume():Boolean Resumes this Task if it is suspended. | Task
|  | setCancelFunction(cancelFunction:Function):void Instruct the DelegateTask to execute the specified Function when it gets cancelled. | DelegateTask
|  | setSkipFunction(skipFunction:Function):void Instruct the DelegateTask to execute the specified Function when its finish method gets executed. | DelegateTask
|  | setSupendFunctions(suspendFunction:Function, resumeFunction:Function):void Instruct the DelegateTask to execute the specified Functions when it gets suspended and resumed. | DelegateTask
|  | skip():Boolean Forces this Task to move to its final state. | Task
|  | start():Boolean Starts this Task. | Task
|  | suspend():Boolean Suspends this Task. | Task

Protected Methods
Show Inherited Protected Methods
Show Inherited Protected Methods

| Method | Defined By
--- | --- | ---
|  | complete():Boolean Signals that this Task has completed. | Task
|  | doCancel():void Called before the CANCEL event gets fired. | Task
|  | doError(message:String):void Called before the ERROR event gets fired. | Task
|  | doResume():void Called before the RESUME event gets fired. | Task
|  | doSkip():void Called after skip has been called but before the COMPLETE event gets fired. | Task
|  | doStart():void Called before the START event gets fired. | Task
|  | doSuspend():void Called before the SUSPEND event gets fired. | Task
|  | doTimeout():void Called before the ERROR event gets fired after a timeout occurred. | Task
|  | error(message:String):Boolean Signals an error condition and cancels the Task. | Task
|  | setCancelable(value:Boolean):void Specifies whether this Task can be cancelled. | Task
|  | setName(name:String):void Sets the name of this Task. | Task
|  | setRestartable(value:Boolean):void Specifies whether this Task can be restarted. | Task
|  | setSkippable(value:Boolean):void Specifies whether this Task can be forced to skip to its final state. | Task
|  | setSuspendable(value:Boolean):void Specifies whether this Task can be suspended. | Task
|  | setTimeout(value:uint):void Sets the timeout for this Task in milliseconds. | Task

Events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | cancel | Dispatched when a Task is cancelled. | Task
|  | complete | Dispatched when a Task has completed its execution. | Task
|  | error | Dispatched when a Task has aborted due to an error condition. | Task
|  | resume | Dispatched when a suspended Task is resumed. | Task
|  | start | Dispatched when a Task is started. | Task
|  | suspend | Dispatched when a Task is suspended. | Task

Constructor Detail

DelegateTask | () | Constructor

`public function DelegateTask(startFunction:Function, name:String = null, isRestartable:Boolean = true, timeout:uint = 0)`

Creates a new instance. The properties `cancelable`, `suspendable` and `finishable` will initially be set to `false` until you set one of the corresponding delegate functions (like `setCancelFunction`).

Parameters

| `startFunction:Function` — the function that gets executed when the Task is started
| `name:String` (default = `null`)`` — an optioanal name for log output
| `isRestartable:Boolean` (default = `true`)`` — whether this DelegateTask is restartable
| `timeout:uint` (default = `0`)`` — an optional timeout in milliseconds

Method Detail

markComplete | () | method

`public function markComplete():Boolean`

Signals that this Task has completed. If this method executes successfully the `COMPLETE` event will be fired.

Returns

| `Boolean` — true if the Task successfully switched its internal state, false if otherwise

markError | () | method |

`public function markError(message:String):Boolean`

Signals an error condition and cancels the Task. If this method executes successfully the `ERROR` event will be fired.

Parameters

| `message:String` — the error description

Returns

| `Boolean` — true if the Task successfully switched its internal state, false if otherwise

setCancelFunction | () | method |

`public function setCancelFunction(cancelFunction:Function):void`

Instruct the DelegateTask to execute the specified Function when it gets cancelled. This method will automatically set the `cancelable` property to true.

Parameters

| `cancelFunction:Function` — the Function to execute when this Task gets cancelled

setSkipFunction | () | method |

`public function setSkipFunction(skipFunction:Function):void`

Instruct the DelegateTask to execute the specified Function when its `finish` method gets executed. This method will automatically set the `skippable` property to true.

Parameters

| `skipFunction:Function` — the Function to execute when the `skip` method of this Task gets executed

setSupendFunctions | () | method |

`public function setSupendFunctions(suspendFunction:Function, resumeFunction:Function):void`

Instruct the DelegateTask to execute the specified Functions when it gets suspended and resumed. This method will automatically set the `suspendable` property to true.

Parameters

| `suspendFunction:Function` — the Function to execute when this Task is suspended
| `resumeFunction:Function` — the Function to execute when this Task is resumed

Thu Jan 16 2014, 01:11 PM +08:00