AsyncResult

From Web Computing Documentation
Revision as of 12:09, 16 August 2011 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

interface AsyncResult <T>

  • henkolib
    • henkolib.async
      • henkolib.async.AsyncResult

Interface overview

Asynchronous functions of the framework usually return an object that implements the AsyncResult interface. It offers methods and event handlers that provide information about the state of the corresponding asynchronous function.

Public functions

isCompleted () : Bool

Returns true if the corresponding asynchronous function has reached the desired final state. Returns false otherwise.

isError ()

Returns true to indicate any possible errors. Returns false otherwise.

getError () : String

Returns an error message if any.

getProgress () : Float

Returns a Float indicating the progress of the corresponding function. Conventionally 0 means 0% while 1.0 means 100%.

getResult () : T

Returns the result of the completed asynchronous function. The return object's type is determined by the template variable.

getElapsedTime () : Date

Returns the time elapsed since the asynchronous function call.

Public variables

onComplete : PublicEvent<T>

The onComplete event handler. You can subscribe to it using its subscribe method.

var result : AsyncResult<someObject> = someAsyncFunction();
result.onComplete.subscribe(function(someObject)
{
    // Do something when someAsyncFunction is completed
});

onError : PublicEvent<String>

The onError event handler. Use its subscribe method like in the above example if you need it.

onProgress : PublicEvent<Float>

The onProgress event handler. You can use this to provide regular updates upon the change of the function's progress.

import package web2grid.core.net.Downloader.hx;
 
var myDownloader = new Downloader();
myDownloader.add("http://server1.com/resource1.txt");
var result = myDownloader.downloadAll();
 
result.onProgress.subscribe(function(p)
{
    myProgressBar.set(p); // updating the UI to indicate the download progress
});
Personal tools
Modules