fm.liveswitch.Promise< T > Class Template Reference

A promise. More...

Public Member Functions

fm.liveswitch.Future< T > fail (fm.liveswitch.IAction1< java.lang.Exception > rejectAction)
 Appends a handler to be executed when the promise is rejected. More...
 
fm.liveswitch.Future< T > fail (fm.liveswitch.IFunction1< java.lang.Exception, fm.liveswitch.Future< T >> rejectFunction)
 Appends a handler to be executed when the promise is rejected. More...
 
 Promise ()
 Creates a new promise. More...
 
 Promise (fm.liveswitch.IAction2< fm.liveswitch.IAction1< T >, fm.liveswitch.IAction1< java.lang.Exception >> callback)
 Creates a promise with a resolve callback and a reject callback. More...
 
fm.liveswitch.Future< T > then (fm.liveswitch.IAction1< T > resolveAction)
 Appends a handler to be executed when the promise is resolved. More...
 
fm.liveswitch.Future< T > then (fm.liveswitch.IAction1< T > resolveAction, fm.liveswitch.IAction1< java.lang.Exception > rejectAction)
 Appends handlers to be executed when the promise is resolved or rejected. More...
 
- Public Member Functions inherited from fm.liveswitch.PromiseBase< T >
boolean castAndResolve (Object result)
 Casts the result and resolves the promise. More...
 
String getId ()
 Gets the identifier of this promise. More...
 
 PromiseBase ()
 Initializes a new instance of the fm.liveswitch.PromiseBase class. More...
 
boolean reject (java.lang.Exception exception)
 Rejects the promise. More...
 
fm.liveswitch.Future< Object > rejectAsync (java.lang.Exception exception)
 Rejects the promise asynchronously. More...
 
boolean resolve (T result)
 Resolves the promise. More...
 
fm.liveswitch.Future< Object > resolveAsync (T result)
 Resolves the promise asynchronously. More...
 
- Public Member Functions inherited from fm.liveswitch.Future< T >
void waitForPromise ()
 Blocks the current thread from proceeding until the future state has been resolved or rejected. More...
 
void waitForPromise (int millisecondsTimeout)
 Blocks the current thread from proceeding until the future state has been resolved or rejected or if the timeout period elapses. More...
 
waitForResult ()
 Blocks the current thread from proceeding until the future has a result. More...
 
waitForResult (int millisecondsTimeout)
 Blocks the current thread from proceeding until the future has a result. More...
 
- Public Member Functions inherited from fm.liveswitch.FutureBase< T >
java.lang.Exception getException ()
 Gets the exception if rejected. More...
 
getResult ()
 Gets the result if resolved. More...
 
fm.liveswitch.FutureState getState ()
 Gets the current state. More...
 

Static Public Member Functions

static fm.liveswitch.Future< Object > wrap (fm.liveswitch.IAction0 callbackAction)
 Creates a promise and resolves it after invoking a callback action, or rejects it if an exception is thrown. More...
 
static< R extends Object > fm.liveswitch.Future< R > wrap (fm.liveswitch.IFunction0< R > callbackFunction)
 Creates a promise and resolves it using the result from a callback function, or rejects it if an exception is thrown. More...
 
static fm.liveswitch.Future< Object > wrapAsync (fm.liveswitch.IAction0 callbackAction)
 Creates a promise and resolves it after invoking a callback action, or rejects it if an exception is thrown. More...
 
static< R extends Object > fm.liveswitch.Future< R > wrapAsync (fm.liveswitch.IFunction0< R > callbackFunction)
 Creates a promise and resolves it using the result from a callback function, or rejects it if an exception is thrown. More...
 
- Static Public Member Functions inherited from fm.liveswitch.PromiseBase< T >
static< R extends Object > fm.liveswitch.Future< R > all (fm.liveswitch.Future< R >[] promises)
 Returns a promise that resolves when all passed in promises resolve. More...
 
static< R extends Object > fm.liveswitch.Future< R > any (fm.liveswitch.Future< R >[] promises)
 Returns a promise that resolves when any passed in promise resolves. More...
 
static< R extends Object > fm.liveswitch.Future< R > delay (int delayMs)
 Create a promise that resolves afer a delay. More...
 
static< R extends Object > fm.liveswitch.Future< R > rejectNow (java.lang.Exception ex)
 Creates a promise and rejects it immediately. More...
 
static fm.liveswitch.Future< Object > resolveNow ()
 Creates a promise and resolves it immediately using a null result value. More...
 
static< R extends Object > fm.liveswitch.Future< R > resolveNow (R result)
 Creates a promise and resolves it immediately using the given result value. More...
 
static< R extends Object > fm.liveswitch.Future< R > wrapPromise (fm.liveswitch.IFunction0< fm.liveswitch.Future< R >> callback)
 Creates a promise and resolves it using the result from a callback function, or rejects it if an exception is thrown. More...
 

Additional Inherited Members

- Protected Member Functions inherited from fm.liveswitch.PromiseBase< T >
void process (fm.liveswitch.IPromise promise, fm.liveswitch.IAction1< T > resolve, fm.liveswitch.IAction1< java.lang.Exception > reject)
 Processes the specified promise. More...
 
- Protected Member Functions inherited from fm.liveswitch.Future< T >
 Future ()
 
- Protected Member Functions inherited from fm.liveswitch.FutureBase< T >
 FutureBase ()
 
void setException (java.lang.Exception value)
 Sets the exception if rejected. More...
 
void setResult (T value)
 Sets the result if resolved. More...
 
void setState (fm.liveswitch.FutureState value)
 Sets the current state. More...
 

Detailed Description

A promise.

Constructor & Destructor Documentation

◆ Promise() [1/2]

Creates a new promise.

◆ Promise() [2/2]

Creates a promise with a resolve callback and a reject callback.

Member Function Documentation

◆ fail() [1/2]

fm.liveswitch.Future<T> fm.liveswitch.Promise< T >.fail ( fm.liveswitch.IAction1< java.lang.Exception >  rejectAction)

Appends a handler to be executed when the promise is rejected.

Parameters
rejectActionThe reject action.

Reimplemented from fm.liveswitch.Future< T >.

◆ fail() [2/2]

fm.liveswitch.Future<T> fm.liveswitch.Promise< T >.fail ( fm.liveswitch.IFunction1< java.lang.Exception, fm.liveswitch.Future< T >>  rejectFunction)

Appends a handler to be executed when the promise is rejected.

Parameters
rejectFunctionThe reject function.

Reimplemented from fm.liveswitch.Future< T >.

◆ then() [1/2]

Appends a handler to be executed when the promise is resolved.

Parameters
resolveActionThe resolve action.

Reimplemented from fm.liveswitch.Future< T >.

◆ then() [2/2]

fm.liveswitch.Future<T> fm.liveswitch.Promise< T >.then ( fm.liveswitch.IAction1< T >  resolveAction,
fm.liveswitch.IAction1< java.lang.Exception >  rejectAction 
)

Appends handlers to be executed when the promise is resolved or rejected.

Parameters
resolveActionThe resolve action.
rejectActionThe reject action.

Reimplemented from fm.liveswitch.Future< T >.

◆ wrap() [1/2]

static fm.liveswitch.Future<Object> fm.liveswitch.Promise< T >.wrap ( fm.liveswitch.IAction0  callbackAction)
static

Creates a promise and resolves it after invoking a callback action, or rejects it if an exception is thrown.

Parameters
callbackActionThe callback action.

◆ wrap() [2/2]

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.Promise< T >.wrap ( fm.liveswitch.IFunction0< R >  callbackFunction)
static

Creates a promise and resolves it using the result from a callback function, or rejects it if an exception is thrown.

Parameters
callbackFunctionThe callback function.

◆ wrapAsync() [1/2]

static fm.liveswitch.Future<Object> fm.liveswitch.Promise< T >.wrapAsync ( fm.liveswitch.IAction0  callbackAction)
static

Creates a promise and resolves it after invoking a callback action, or rejects it if an exception is thrown.

The callback is always dispatched to the background.

Parameters
callbackActionThe callback action.

◆ wrapAsync() [2/2]

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.Promise< T >.wrapAsync ( fm.liveswitch.IFunction0< R >  callbackFunction)
static

Creates a promise and resolves it using the result from a callback function, or rejects it if an exception is thrown.

The callback is always dispatched to the background.

Parameters
callbackFunctionThe callback function.