API DocumentationAll Packages | All Classes | Index | Frames
AsyncHandler
 
Packageorg.flexunit.async
Classpublic class AsyncHandler
InheritanceAsyncHandler Inheritance flash.events.EventDispatcher

AsyncHandlers are created when the developer calls the TestCase.asyncHandler() method. This causes the TestMethod to pend until the named event fires or the timeout is reached, effectively preventing the method from failing or passing until all outstanding asynchronous activity is resolved.



Public Properties
 PropertyDefined By
  EVENT_FIRED : String = eventFired
[static]
AsyncHandler
  eventHandler : Function
A reference to the event handler that should be called if the event named in the TestCase.asyncHandler() method fires before the timeout is reached.
AsyncHandler
  passThroughData : Object = null
A generic object that is optionally provided by the developer when starting a new asynchronous operation.
AsyncHandler
  timeout : int
The number of milliseconds this class should wait for its handleEvent method to be called, before firing a 'timerExpired' event.
AsyncHandler
  timeoutHandler : Function = null
A reference to the event handler that should be called if the event named in the TestCase.asyncHandler() method does not fire before the timeout is reached.
AsyncHandler
  TIMER_EXPIRED : String = timerExpired
[static]
AsyncHandler
Public Methods
 MethodDefined By
  
AsyncHandler(eventHandler:Function, timeout:int = 0, passThroughData:Object = null, timeoutHandler:Function = null)
Constructor.
AsyncHandler
  
handleEvent(event:Event = null):void
A generic handler called by an unknown object when a specific event fires.
AsyncHandler
  
handleTimeout(event:TimerEvent):void
An event handler that is called by our timer if handleEvent is not called before the number of milliseconds specified in the timeout property.
AsyncHandler
  
startTimer():void
Starts the timeout timer for this test.
AsyncHandler
Events
 Event Summary Defined By
  The 'eventFired' event is fired when the event specified in the TestCase.asyncHandler() method occurs.AsyncHandler
  The 'timerExpired' event is fired when the event specified in the TestCase.asyncHandler() method does not occur before the timeout specified in the constructor.AsyncHandler
Property Detail
EVENT_FIREDproperty
public static var EVENT_FIRED:String = eventFired

eventHandlerproperty 
public var eventHandler:Function

A reference to the event handler that should be called if the event named in the TestCase.asyncHandler() method fires before the timeout is reached. The handler is expected to have the follow signature: public function handleEvent( event:Event, passThroughData:Object ):void { } The first parameter is the original event object. The second parameter is a generic object that can optionally be provided by the developer when starting a new asynchronous operation.

passThroughDataproperty 
public var passThroughData:Object = null

A generic object that is optionally provided by the developer when starting a new asynchronous operation. This generic object is passed to the eventHandler function if it is called.

timeoutproperty 
public var timeout:int

The number of milliseconds this class should wait for its handleEvent method to be called, before firing a 'timerExpired' event.

timeoutHandlerproperty 
public var timeoutHandler:Function = null

A reference to the event handler that should be called if the event named in the TestCase.asyncHandler() method does not fire before the timeout is reached. The handler is expected to have the follow signature: public function handleTimeoutEvent( passThroughData:Object ):void { } The parameter is a generic object that can optionally be provided by the developer when starting a new asynchronous operation.

TIMER_EXPIREDproperty 
public static var TIMER_EXPIRED:String = timerExpired

Constructor Detail
AsyncHandler()Constructor
public function AsyncHandler(eventHandler:Function, timeout:int = 0, passThroughData:Object = null, timeoutHandler:Function = null)

Constructor.

Parameters
eventHandler:Function — Method to call when an event occurs.
 
timeout:int (default = 0) — Number of milliseconds to wait for an event.
 
passThroughData:Object (default = null) — A generic object that can optionally be provided by the developer when setting up an synchronous test.
 
timeoutHandler:Function (default = null) — A method to call if the timeout occurs before the event.
Method Detail
handleEvent()method
public function handleEvent(event:Event = null):void

A generic handler called by an unknown object when a specific event fires. The object and event are known in the TestCase when calling the TestCase.asyncHandler(). This class respond to the event by firing a 'eventFired' event if the event occurred before the specified timeout.

Parameters

event:Event (default = null) — The event being listened for.

handleTimeout()method 
public function handleTimeout(event:TimerEvent):void

An event handler that is called by our timer if handleEvent is not called before the number of milliseconds specified in the timeout property. This method dispatches the 'timerExpired' event to inform the testCase.

Parameters

event:TimerEvent

startTimer()method 
public function startTimer():void

Starts the timeout timer for this test. This method is called by the testCase at the end of the method body

Event Detail
eventFired Event
Event Object Type: org.flexunit.events.AsyncEvent

The 'eventFired' event is fired when the event specified in the TestCase.asyncHandler() method occurs. The TestCase pends on this event or the 'timerExpired' event before moving on to the next test method or asynchronous event.

timerExpired Event  
Event Object Type: flash.events.Event

The 'timerExpired' event is fired when the event specified in the TestCase.asyncHandler() method does not occur before the timeout specified in the constructor. The TestCase pends on this event or the 'eventFired' event before continuing to the next test method or asynhronouse event.