Did this page help you?

   Yes   No   Tell us about it...

com.amazonaws.services.simpleworkflow.flow.core
Class Promise<V>

java.lang.Object
  extended by com.amazonaws.services.simpleworkflow.flow.core.Promise<V>
Type Parameters:
V - The result type returned by this Promise's get method. Use Void to represent Promise that indicates completion of operation that doesn't return a value.
Direct Known Subclasses:
AndPromise, Functor, OrPromise, Settable

public abstract class Promise<V>
extends java.lang.Object

Promise is a future like object that is used as a placeholder for a result of an asynchronous API. Java Future is a synchronization construct that is used to block a thread that called get() method if result is not available yet. Promise differs from it as it cannot be used for blocking. A call to its get() method throws IllegalStateException if result is not available yet. The correct way to ensure that Promise is ready is to access it from a method that is annotated as @Asynchronous and have the given Promise as one its arguments or from Task.doExecute() method assuming that promise was passed to the Task as a constructor parameter.

Promise is not linked to error handling like Future is. In case of exceptions they are propagated to the TryCatchFinally.doCatch(Throwable) method of the TryCatchFinally that owns the asynchronous task that failed. See TryCatchFinally for more info on the error handling.

For promises that don't need a value and just used to ensure correct ordering of asynchronous operations the common pattern to use Void as a generic type.


Constructor Summary
Promise()
           
 
Method Summary
static
<T> Promise<T>
asPromise(T value)
          Convenience method for creating a Promise object which is in ready state and returns the passed in value when get() is called.
abstract  V get()
           
 java.lang.String getDescription()
           
abstract  boolean isReady()
           
static Promise<java.lang.Void> Void()
          This is a factory method to create a Promise object in ready state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Promise

public Promise()
Method Detail

get

public abstract V get()
Returns:
result of your asynchronous computation
Throws:
java.lang.IllegalStateException - if result of your asynchronous computation is not available yet

isReady

public abstract boolean isReady()
Returns:
true if the result of your asynchronous computation is available

getDescription

public java.lang.String getDescription()
Returns:
human friendly description on what this promise represents. Emitted for example as part of AsyncScope.getAsynchronousThreadDumpAsString()

asPromise

public static <T> Promise<T> asPromise(T value)
Convenience method for creating a Promise object which is in ready state and returns the passed in value when get() is called.

The same as new Settable(value)

Type Parameters:
T - Type of value
Parameters:
value - Object to return when get() is called
Returns:
An instance of Promise wrapper object

Void

public static Promise<java.lang.Void> Void()
This is a factory method to create a Promise object in ready state.

Returns:
An instance of Promise object with no value.


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.