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

Package | org.spicefactory.lib.task
Class | public class ResultTask
Inheritance | ResultTask Task flash.events.EventDispatcher
Subclasses | XmlLoaderTask

Abstract base class for asynchronous operations that produce a result. This may be a loading operation or a remote service invocation.

With the optional `propertyName` parameter of the constructor you can specify a property that will be set in the value of the data property. Since the data property of any Task is recursive (if it wasn't set for a particular Task it uses the value of its parent TaskGroup), you can use an object that was set as the data property on a containing TaskGroup to collect values of different ResultTasks. This way you don't have to keep references to all individual Tasks just to retrieve the result after the asynchronous operation is finished.

In the following example a simple value object will be used to collect the loaded text and XML of two loader tasks:

`

     public class LoaderResult {

         public var text:String;
         public var xml:XML;

     }

     var group:TaskGroup = new SequentialTaskGroup();
     group.data = new LoaderResult();
     group.addTask(new TextLoaderTask("test.txt", "text"));
     group.addTask(new XmlLoaderTask("test.xml", "xml"));
     group.addEventListener(TaskEvent.COMPLETE, onComplete);
     // error handling omitted
     group.start();

     private function onComplete (event:TaskEvent) : void {
         var t:Task = event.target as Task;
         var result:LoaderResult = t.data as LoaderResult;
         trace("loaded text: " result.text);
         trace("loaded XML: " result.xml);
     }

`

Note that the two loader tasks of the above example (`TextLoaderTask` and `XmlLoaderTask`) are not part of the Spicelib (yet). They are just used for illustration purposes. This example only works if the constructor of these two classes passes the second argument to the constructor of the superclass (`ResultTask`). Instead of a concrete class like `LoaderResult` in the example above you can also use a simple `Dictionary` as the data property.

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
|  | result : * [read-only] The result produced by this Task. | ResultTask
|  | 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
--- | --- | ---
|  | ResultTask(propertyName:String = null) Creates a new ResultTask instance. | ResultTask
|  | cancel():Boolean Cancels this Task. | Task
|  | resume():Boolean Resumes this Task if it is suspended. | Task
|  | 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
|  | setResult(result:*):Boolean Sets the result produced by this Task and signals that this Task has completed. | ResultTask
|  | 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

Property Detail

result | property

`result:*` [read-only]

The result produced by this Task. If the Task has not completed yet, was cancelled or finished with an error this property is undefined.

Implementation
`public function get result():*`
Constructor Detail

ResultTask | () | Constructor

`public function ResultTask(propertyName:String = null)`

Creates a new ResultTask instance. The optional `propertyName` parameter can be used to specify a property that will be set on the value of the data property of this Task or one of its parents.

Parameters

| `propertyName:String` (default = `null`)``

Method Detail

setResult | () | method

`protected function setResult(result:*):Boolean`

Sets the result produced by this Task and signals that this Task has completed. Subclasses should call this method when the asynchronous operation has completed. If this method executes successfully the `COMPLETE` event will be fired.

This method should be used instead of the `complete` method from the Task superclass.

Parameters

| `result:*`

Returns

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

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