org.appcelerator.kroll.common
Class AsyncResult

java.lang.Object
  extended by java.util.concurrent.Semaphore
      extended by org.appcelerator.kroll.common.AsyncResult
All Implemented Interfaces:
Serializable

public class AsyncResult
extends Semaphore

This is a semaphore that blocks the current thread when getResult() is called until another thread calls setResult(). See TiMessenger.sendBlockingMainMessage(android.os.Message, Object) for an example use case.

See Also:
Serialized Form

Constructor Summary
AsyncResult()
          Constructs an AsyncResult with no argument.
AsyncResult(Object arg)
          Constructs an AsyncResult with an argument.
 
Method Summary
 Object getArg()
           
 Object getResult()
           
 void setException(Throwable exception)
          Sets an exception to be thrown to the code that is blocking on setResult(Object), and releases the lock.
 void setResult(Object result)
          Sets the result asynchronously, releasing the lock.
 

Constructor Detail

AsyncResult

public AsyncResult()
Constructs an AsyncResult with no argument.


AsyncResult

public AsyncResult(Object arg)
Constructs an AsyncResult with an argument.

Parameters:
arg - the general user data for a Message.
Method Detail

getArg

public Object getArg()
Returns:
the arg object that is passed into the constructor.

setResult

public void setResult(Object result)
Sets the result asynchronously, releasing the lock.

Parameters:
result - the resulting object.

setException

public void setException(Throwable exception)
Sets an exception to be thrown to the code that is blocking on setResult(Object), and releases the lock.

Parameters:
exception - a thrown exception. It can be thrown from any place that handles an AsyncResult.

getResult

public Object getResult()
Returns:
the result, blocking the current thread until another thread calls getResult()


Copyright © 2010-2012 Appcelerator, Inc. Licensed under the Apache License 2.0