Packagecom.rosettastone.library.taskmanager
Classpublic class Task
InheritanceTask Inheritance flash.events.EventDispatcher
Implements ITask
Subclasses AbstractCompositeTask, AbstractTaskManager, InterruptibleTask, ObserverTask, StubTask, SynchronousTask, TaskWithClosure

This class is meant to encapsulate a single, self-contained job. Each instance can have 0+ dependencies in the form of other tasks. To create a usable Task, extend this class and override the customRun() method. Your Task should call taskComplete() or taskError() when it has completed or failed.



Public Properties
 PropertyDefined By
  data : *
[read-only] Optional data parameter passed to the Task complete/error/interruption method.
Task
  id : Number
[read-only]
Task
  interruptible : Boolean
[read-only] The current Task can be interrupted.
Task
  interruptingTask : ITask
[read-only] The Task currently interrupting the composite Task's execution (or NULL if no such Task exists).
Task
  isComplete : Boolean
[read-only] The current task has successfully completed execution.
Task
  isErrored : Boolean
[read-only] The current task failed.
Task
  isInterrupted : Boolean
[read-only]
Task
  isRunning : Boolean
[read-only] The task is currently running.
Task
  message : String
[read-only] Optional message parameter passed to the task complete/error/interruption method.
Task
  numInternalOperations : int
[read-only] Number of internal operations conducted by this task.
Task
  numInternalOperationsCompleted : int
[read-only] Number of internal operations that have completed.
Task
  numInternalOperationsPending : int
[read-only] Number of internal operations not yet completed.
Task
  numTimesCompleted : int
[read-only] Number of times this task has completed.
Task
  numTimesErrored : int
[read-only] Number of times this task has errored.
Task
  numTimesInterrupted : int
[read-only] Number of times this task has been interrupted.
Task
  numTimesReset : int
[read-only] Number of times this task has been reset.
Task
  numTimesStarted : int
[read-only] Number of times this task has been started.
Task
  running : Boolean
[read-only] The task is currently running.
Task
  synchronous : Boolean
[read-only] The current task can be executed synchronously.
Task
  taskIdentifier : String
(Optional) human-readable label for task.
Task
  uniqueID : Number
[read-only] Unique ID for a task.
Task
Protected Properties
 PropertyDefined By
  logger : ILogger
[read-only] Instance of ILogger to be used for any custom Task logging.
Task
Public Methods
 MethodDefined By
  
Task(taskIdentifier:String = null)
Constructor
Task
  
and(... chainedTasks):ITask
Executes the specified tasks when the current task is executed.
Task
  
Task
  
interrupt():Boolean
Interruptible tasks should override interrupt() and get interruptible() if they are interruptible.
Task
  
interruptForTask(interruptingTask:ITask):Boolean
Interrupts the current Task to wait on the Task specified.
Task
  
or(... chainedTasks):ITask
Executes the specified tasks if the current task fails.
Task
  
reset():void
Resets the task to it's pre-run state.
Task
  
Starts a task.
Task
  
then(... chainedTasks):ITask
Executes the specified tasks once the current task has completed successfully.
Task
  
withCompleteHandler(completeHandler:Function):ITask
Although tasks dispatch TaskEvents to indicate completion, this method may also be used for notification purposes.
Task
  
withErrorHandler(errorHandler:Function):ITask
Although tasks dispatch TaskEvents to indicate failure, this method may also be used for notification purposes.
Task
  
withFinalHandler(finalHandler:Function):ITask
This handler is invoked upon either success or failure of the Task.
Task
  
withInterruptionHandler(interruptionHandler:Function):ITask
Task
  
withStartedHandler(startedHandler:Function):ITask
Although tasks dispatch TaskEvents to indicate starting, this method may also be used for notification purposes.
Task
Protected Methods
 MethodDefined By
  
Override this method to perform any custom reset operations.
Task
  
customRun():void
Override this method to give your Task functionality.
Task
  
Task
  
getLoggerString(string:String):String
Returns a string for logging the specified task-state event.
Task
  
taskComplete(message:String, data:* = null):void
This method should be called upon Task completion.
Task
  
taskError(message:String, data:* = null):void
This method should be called upon Task failure.
Task
  
taskInterrupted(message:String, data:* = null):void
Call this method to interrupt the currently running Task.
Task
  
Task
Events
 Event Summary Defined By
  Task
  Task
  Task
  Task
  Task
  Task
Property Detail
_completeproperty
TaskPrivateNamespace var _complete:Boolean = false

_completeHandlersproperty 
TaskPrivateNamespace var _completeHandlers:Array

_dataproperty 
TaskPrivateNamespace var _data:*

_erroredproperty 
TaskPrivateNamespace var _errored:Boolean

_errorHandlersproperty 
TaskPrivateNamespace var _errorHandlers:Array

_finalHandlersproperty 
TaskPrivateNamespace var _finalHandlers:Array

_interruptedproperty 
TaskPrivateNamespace var _interrupted:Boolean

_interruptingTaskproperty 
TaskPrivateNamespace var _interruptingTask:ITask

_interruptionHandlersproperty 
TaskPrivateNamespace var _interruptionHandlers:Array

_loggerproperty 
TaskPrivateNamespace var _logger:ILogger

_messageproperty 
TaskPrivateNamespace var _message:String

_numTimesCompletedproperty 
TaskPrivateNamespace var _numTimesCompleted:int

_numTimesErroredproperty 
TaskPrivateNamespace var _numTimesErrored:int

_numTimesInterruptedproperty 
TaskPrivateNamespace var _numTimesInterrupted:int

_numTimesResetproperty 
TaskPrivateNamespace var _numTimesReset:int

_numTimesStartedproperty 
TaskPrivateNamespace var _numTimesStarted:int

_runningproperty 
TaskPrivateNamespace var _running:Boolean = false

_startedHandlersproperty 
TaskPrivateNamespace var _startedHandlers:Array

_taskHasBeenRunAtLeastOnceproperty 
TaskPrivateNamespace var _taskHasBeenRunAtLeastOnce:Boolean

_taskIdentifierproperty 
TaskPrivateNamespace var _taskIdentifier:String

_uniqueIDproperty 
TaskPrivateNamespace var _uniqueID:Number

dataproperty 
data:*  [read-only]

Optional data parameter passed to the Task complete/error/interruption method.


Implementation
    public function get data():*
idproperty 
id:Number  [read-only]


Implementation
    public function get id():Number
IDproperty 
TaskPrivateNamespace static var ID:Number = 0

interruptibleproperty 
interruptible:Boolean  [read-only]

The current Task can be interrupted. Invoking interrupt() for a Task that is not marked as interruptible may result in an error.


Implementation
    public function get interruptible():Boolean
interruptingTaskproperty 
interruptingTask:ITask  [read-only]

The Task currently interrupting the composite Task's execution (or NULL if no such Task exists).


Implementation
    public function get interruptingTask():ITask
isCompleteproperty 
isComplete:Boolean  [read-only]

The current task has successfully completed execution.


Implementation
    public function get isComplete():Boolean
isErroredproperty 
isErrored:Boolean  [read-only]

The current task failed.


Implementation
    public function get isErrored():Boolean
isInterruptedproperty 
isInterrupted:Boolean  [read-only]


Implementation
    public function get isInterrupted():Boolean
isRunningproperty 
isRunning:Boolean  [read-only]

The task is currently running. This value is FALSE if the task has not been run, has completed run (succesfully or due to a failure), or has been interrupted.


Implementation
    public function get isRunning():Boolean
loggerproperty 
logger:ILogger  [read-only]

Instance of ILogger to be used for any custom Task logging.


Implementation
    protected function get logger():ILogger
messageproperty 
message:String  [read-only]

Optional message parameter passed to the task complete/error/interruption method.


Implementation
    public function get message():String
numInternalOperationsproperty 
numInternalOperations:int  [read-only]

Number of internal operations conducted by this task. Sub-classes should override this method if containing a value > 1; If value > 1, task should dispatch ProgressEvent.PROGRESS events manually to indicate changes in numInternalOperationsCompleted. If value == 1, task will automatically dispatching ProgressEvent.PROGRESS events.


Implementation
    public function get numInternalOperations():int
numInternalOperationsCompletedproperty 
numInternalOperationsCompleted:int  [read-only]

Number of internal operations that have completed. Sub-classes should override this method if containing a value > 1;


Implementation
    public function get numInternalOperationsCompleted():int
numInternalOperationsPendingproperty 
numInternalOperationsPending:int  [read-only]

Number of internal operations not yet completed.


Implementation
    public function get numInternalOperationsPending():int
numTimesCompletedproperty 
numTimesCompleted:int  [read-only]

Number of times this task has completed.


Implementation
    public function get numTimesCompleted():int
numTimesErroredproperty 
numTimesErrored:int  [read-only]

Number of times this task has errored.


Implementation
    public function get numTimesErrored():int
numTimesInterruptedproperty 
numTimesInterrupted:int  [read-only]

Number of times this task has been interrupted.


Implementation
    public function get numTimesInterrupted():int
numTimesResetproperty 
numTimesReset:int  [read-only]

Number of times this task has been reset. This is the only counter that is not reset by the reset() method.


Implementation
    public function get numTimesReset():int
numTimesStartedproperty 
numTimesStarted:int  [read-only]

Number of times this task has been started.


Implementation
    public function get numTimesStarted():int
runningproperty 
running:Boolean  [read-only]

The task is currently running. This value is FALSE if the task has not been run, has completed run (succesfully or due to a failure), or has been interrupted.


Implementation
    public function get running():Boolean
synchronousproperty 
synchronous:Boolean  [read-only]

The current task can be executed synchronously.


Implementation
    public function get synchronous():Boolean
taskIdentifierproperty 
taskIdentifier:String

(Optional) human-readable label for task.


Implementation
    public function get taskIdentifier():String
    public function set taskIdentifier(value:String):void
uniqueIDproperty 
uniqueID:Number  [read-only]

Unique ID for a task.


Implementation
    public function get uniqueID():Number
Constructor Detail
Task()Constructor
public function Task(taskIdentifier:String = null)

Constructor

Parameters
taskIdentifier:String (default = null) — Human-friendly ID string useful for debugging purposes only.
Method Detail
and()method
public function and(... chainedTasks):ITask

Executes the specified tasks when the current task is executed. If the current task has already been started the new tasks will be executed immediately. Failures or interruptions in the current task will not affect the chained tasks.

Parameters

... chainedTasks — One or more tasks

Returns
ITask
customReset()method 
protected function customReset():void

Override this method to perform any custom reset operations.

customRun()method 
protected function customRun():void

Override this method to give your Task functionality.

disconnectFromInterruptingTask()method 
public function disconnectFromInterruptingTask():void

dispatchProgressEvent()method 
protected function dispatchProgressEvent():void

doTaskComplete()method 
TaskPrivateNamespace function doTaskComplete(message:String, data:* = null):void

Parameters

message:String
 
data:* (default = null)

doTaskError()method 
TaskPrivateNamespace function doTaskError(message:String, data:* = null):void

Parameters

message:String
 
data:* (default = null)

doTaskInterrupted()method 
TaskPrivateNamespace function doTaskInterrupted(message:String, data:* = null):void

Parameters

message:String
 
data:* (default = null)

getLoggerString()method 
protected function getLoggerString(string:String):String

Returns a string for logging the specified task-state event.

Parameters

string:String — String to append to log

Returns
String
interrupt()method 
public function interrupt():Boolean

Interruptible tasks should override interrupt() and get interruptible() if they are interruptible. If they are, they should fire a TaskEvent.INTERRUPTED to indicate successful interruption of the task. If the interrupting fails at runtime, this method returns false

Returns
Boolean
interruptForTask()method 
public function interruptForTask(interruptingTask:ITask):Boolean

Interrupts the current Task to wait on the Task specified. Once this Task dispatches a TaskEvent.COMPLETE event, this Task will resume. If the specified Task dispatches a TaskEvent.ERROR event this Task will also error. TaskEvent.INTERRUPTED events are ignored. If this method is called once with a Task and then called again before that Task has completed, Event listeners will be removed from the first Task and added to the second one. There can only be 1 active interrupting Task at a time. If this Task should be interrupted by more than one Task, a CompositeTask or ObserverTask should be used. If the specified interrupting Task is already running this method will simply add event listeners. If it is not running this method will add event listeners but will rely on external code to run the interrupter.

Parameters

interruptingTask:ITask — Task

Returns
Boolean
onInterruptingTaskComplete()method 
TaskPrivateNamespace function onInterruptingTaskComplete(event:TaskEvent):void

Parameters

event:TaskEvent

onInterruptingTaskError()method 
TaskPrivateNamespace function onInterruptingTaskError(event:TaskEvent):void

Parameters

event:TaskEvent

or()method 
public function or(... chainedTasks):ITask

Executes the specified tasks if the current task fails.

Parameters

... chainedTasks — One or more tasks

Returns
ITask
reset()method 
public function reset():void

Resets the task to it's pre-run state. This allows it to be re-run. This method can only be called on non-running tasks.

run()method 
public final function run():ITask

Starts a task. This method will dispatch a TaskEvent.STARTED to indicate that the task has begun. This method may also be used to retry/resume an errored task.

Returns
ITask
taskComplete()method 
protected function taskComplete(message:String, data:* = null):void

This method should be called upon Task completion. It dispatches a TaskEvent.COMPLETE event and toggles the Tasks's "running" and "complete" states. It also invokes the success handler if one has been provided.

Parameters

message:String — An (optional) message or data in string form
 
data:* (default = null) — Optional data object related to the Task dispatching this event.

taskError()method 
protected function taskError(message:String, data:* = null):void

This method should be called upon Task failure. It dispatches a TaskEvent.ERROR event and toggles the Tasks's "running" and "complete" states. It also invokes the error handler if one has been provided.

Parameters

message:String — An (optional) reason for the error
 
data:* (default = null) — Optional data object containing additional error information

taskInterrupted()method 
protected function taskInterrupted(message:String, data:* = null):void

Call this method to interrupt the currently running Task. This method dispatches a TaskEvent.INTERRUPTED and toggles the tasks's "running" state.

Parameters

message:String — An (optional) reason for the interruption
 
data:* (default = null)

then()method 
public function then(... chainedTasks):ITask

Executes the specified tasks once the current task has completed successfully.

Parameters

... chainedTasks — One or more tasks

Returns
ITask
throwErrorIfAnyObjectInArrayIsNotATask()method 
protected function throwErrorIfAnyObjectInArrayIsNotATask(tasks:Array):void

Parameters

tasks:Array

withCompleteHandler()method 
public function withCompleteHandler(completeHandler:Function):ITask

Although tasks dispatch TaskEvents to indicate completion, this method may also be used for notification purposes. The provided function will be invoked only upon successful completion of the task. This method may be called multiple times safely; each unique function specified will be executed once when the task completes.

It should have one of the following signatures:

function( message:String = "", data:= null ):void
function():void

Parameters

completeHandler:Function — Function

Returns
ITask
withErrorHandler()method 
public function withErrorHandler(errorHandler:Function):ITask

Although tasks dispatch TaskEvents to indicate failure, this method may also be used for notification purposes. The provided function will be invoked only upon failure of the task. This method may be called multiple times safely; each unique function specified will be executed once if the tasks errors.

It should have one of the following signatures:

function( message:String = "", data:= null ):void
function():void

Parameters

errorHandler:Function — Function

Returns
ITask
withFinalHandler()method 
public function withFinalHandler(finalHandler:Function):ITask

This handler is invoked upon either success or failure of the Task. It can be used for cleanup that must be done regardless of Task-status.

This method may be called multiple times safely. Each unique function specified will be executed once when the task is ready for cleanup.

This type of closure should implement the following signature:

function():void

Parameters

finalHandler:Function

Returns
ITask
withInterruptionHandler()method 
public function withInterruptionHandler(interruptionHandler:Function):ITask

Parameters

interruptionHandler:Function

Returns
ITask
withStartedHandler()method 
public function withStartedHandler(startedHandler:Function):ITask

Although tasks dispatch TaskEvents to indicate starting, this method may also be used for notification purposes. The provided function will be invoked each time the task is started (or re-started). This method may be called multiple times safely; each unique function specified will be executed once when the task starts.

It should have the following signature:

function():void

Parameters

startedHandler:Function — Function

Returns
ITask
Event Detail
progress Event
Event Object Type: flash.events.ProgressEvent

taskEventComplete Event  
Event Object Type: com.rosettastone.library.taskmanager.events.TaskEvent

taskEventError Event  
Event Object Type: com.rosettastone.library.taskmanager.events.TaskEvent

taskEventFinal Event  
Event Object Type: com.rosettastone.library.taskmanager.events.TaskEvent

taskEventInterrupted Event  
Event Object Type: com.rosettastone.library.taskmanager.events.TaskEvent

taskEventStarted Event  
Event Object Type: com.rosettastone.library.taskmanager.events.TaskEvent