Packagecom.rosettastone.library.taskmanager
Interfacepublic interface ITask extends flash.events.IEventDispatcher
Implementors Task

A Task represents a job. This job can be synchronous or asynchronous. It can be a simple operation or a composite of other Tasks. This interface defines the minimum API that must be implemented by a Task within the Task Manager framework.



Public Properties
 PropertyDefined By
  data : *
[read-only] Optional data parameter passed to the Task complete/error/interruption method.
ITask
  isComplete : Boolean
[read-only] The current task has successfully completed execution.
ITask
  isErrored : Boolean
[read-only] The current task failed.
ITask
  isRunning : Boolean
[read-only] The task is currently running.
ITask
  message : String
[read-only] Optional message parameter passed to the task complete/error/interruption method.
ITask
  numInternalOperations : int
[read-only] Number of internal operations conducted by this task.
ITask
  numInternalOperationsCompleted : int
[read-only] Number of internal operations that have completed.
ITask
  numInternalOperationsPending : int
[read-only] Number of internal operations not yet completed.
ITask
  numTimesCompleted : int
[read-only] Number of times this task has completed.
ITask
  numTimesErrored : int
[read-only] Number of times this task has errored.
ITask
  numTimesInterrupted : int
[read-only] Number of times this task has been interrupted.
ITask
  numTimesReset : int
[read-only] Number of times this task has been reset.
ITask
  numTimesStarted : int
[read-only] Number of times this task has been started.
ITask
  running : Boolean
[read-only] The task is currently running.
ITask
  synchronous : Boolean
[read-only] The current task can be executed synchronously.
ITask
  taskIdentifier : String
(Optional) human-readable label for task.
ITask
  uniqueID : Number
[read-only] Unique ID for a task.
ITask
Public Methods
 MethodDefined By
  
and(... chainedTasks):ITask
Executes the specified tasks when the current task is executed.
ITask
  
or(... chainedTasks):ITask
Executes the specified tasks if the current task fails.
ITask
  
reset():void
Resets the task to it's pre-run state.
ITask
  
Starts a task.
ITask
  
then(... chainedTasks):ITask
Executes the specified tasks once the current task has completed successfully.
ITask
  
withCompleteHandler(completeHandler:Function):ITask
Although tasks dispatch TaskEvents to indicate completion, this method may also be used for notification purposes.
ITask
  
withErrorHandler(errorHandler:Function):ITask
Although tasks dispatch TaskEvents to indicate failure, this method may also be used for notification purposes.
ITask
  
withFinalHandler(finalHandler:Function):ITask
This handler is invoked upon either success or failure of the Task.
ITask
  
withStartedHandler(startedHandler:Function):ITask
Although tasks dispatch TaskEvents to indicate starting, this method may also be used for notification purposes.
ITask
Events
 Event Summary Defined By
  ITask
  ITask
  ITask
  ITask
  ITask
Property Detail
dataproperty
data:*  [read-only]

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


Implementation
    public function get data():*
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
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
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
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

Throws
Error — if any parameter is not a task

Example

var initialTask:StubTask = new StubTask();
var parallelTask:StubTask = new StubTask();

initialTask.and( parallelTask ).run();
or()method 
public function or(... chainedTasks):ITask

Executes the specified tasks if the current task fails.

Parameters

... chainedTasks — One or more tasks

Returns
ITask

Throws
Error — if any parameter is not a task

Example

var initialTask:StubTask = new StubTask();
var fallbackTask:StubTask = new StubTask();

initialTask.or( fallbackTask ).run();
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 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
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

Throws
Error — if any parameter is not a task

Example

var firstTask:StubTask = new StubTask();
var secondTask:StubTask = new StubTask();

firstTask.then( secondTask ).run();
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
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

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