fm.liveswitch.PromiseBase< T > Class Template Referenceabstract

Promise base properties/methods. More...

Public Member Functions

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 >
abstract fm.liveswitch.Future< T > fail (fm.liveswitch.IAction1< java.lang.Exception > rejectAction)
 Appends a handler to be executed when the promise is rejected. More...
 
abstract 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...
 
abstract fm.liveswitch.Future< T > then (fm.liveswitch.IAction1< T > resolveAction)
 Appends a handler to be executed when the promise is resolved. More...
 
abstract 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...
 
abstract< R extends Object > fm.liveswitch.Future< R > then (fm.liveswitch.IFunction1< T, fm.liveswitch.Future< R >> resolveFunction)
 Appends a handler to be executed when the promise is resolved. More...
 
abstract< R extends Object > fm.liveswitch.Future< R > then (fm.liveswitch.IFunction1< T, fm.liveswitch.Future< R >> resolveFunction, fm.liveswitch.IAction1< java.lang.Exception > rejectAction)
 Appends handlers to be executed when the promise is resolved or rejected. More...
 
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< 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...
 

Protected Member Functions

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

Promise base properties/methods.

Constructor & Destructor Documentation

◆ PromiseBase()

Initializes a new instance of the fm.liveswitch.PromiseBase class.

Member Function Documentation

◆ all()

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.PromiseBase< T >.all ( fm.liveswitch.Future< R >[]  promises)
static

Returns a promise that resolves when all passed in promises resolve.

Parameters
promisesThe promises to check.

◆ any()

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.PromiseBase< T >.any ( fm.liveswitch.Future< R >[]  promises)
static

Returns a promise that resolves when any passed in promise resolves.

Parameters
promisesThe promises to check.

◆ castAndResolve()

boolean fm.liveswitch.PromiseBase< T >.castAndResolve ( Object  result)

Casts the result and resolves the promise.

Will throw an exception if the cast fails.

Parameters
resultThe result.

Implements fm.liveswitch.IPromise.

◆ delay()

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.PromiseBase< T >.delay ( int  delayMs)
static

Create a promise that resolves afer a delay.

Parameters
delayMs

◆ getId()

String fm.liveswitch.PromiseBase< T >.getId ( )

Gets the identifier of this promise.

◆ process()

void fm.liveswitch.PromiseBase< T >.process ( fm.liveswitch.IPromise  promise,
fm.liveswitch.IAction1< T >  resolve,
fm.liveswitch.IAction1< java.lang.Exception >  reject 
)
protected

Processes the specified promise.

Parameters
promiseThe promise.
resolveThe resolve.
rejectThe reject.

◆ reject()

boolean fm.liveswitch.PromiseBase< T >.reject ( java.lang.Exception  exception)

Rejects the promise.

Parameters
exceptionThe exception.

Implements fm.liveswitch.IPromise.

◆ rejectAsync()

fm.liveswitch.Future<Object> fm.liveswitch.PromiseBase< T >.rejectAsync ( java.lang.Exception  exception)

Rejects the promise asynchronously.

Parameters
exceptionThe exception.

◆ rejectNow()

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.PromiseBase< T >.rejectNow ( java.lang.Exception  ex)
static

Creates a promise and rejects it immediately.

Parameters
exThe exception.

◆ resolve()

boolean fm.liveswitch.PromiseBase< T >.resolve ( result)

Resolves the promise.

Parameters
resultThe result.

◆ resolveAsync()

fm.liveswitch.Future<Object> fm.liveswitch.PromiseBase< T >.resolveAsync ( result)

Resolves the promise asynchronously.

Parameters
resultThe result.

◆ resolveNow() [1/2]

static fm.liveswitch.Future<Object> fm.liveswitch.PromiseBase< T >.resolveNow ( )
static

Creates a promise and resolves it immediately using a null result value.

◆ resolveNow() [2/2]

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.PromiseBase< T >.resolveNow ( result)
static

Creates a promise and resolves it immediately using the given result value.

Parameters
resultThe result.

◆ wrapPromise()

static <R extends Object> fm.liveswitch.Future<R> fm.liveswitch.PromiseBase< T >.wrapPromise ( fm.liveswitch.IFunction0< fm.liveswitch.Future< R >>  callback)
static

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

Parameters
callbackThe callback function.