public abstract class PromiseBase<T> extends java.lang.Object implements Promise<T>
Promise implementation sans then, except, and always.| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Object |
lock
Use this as a lock against which you can synchronize the state.
|
| Constructor and Description |
|---|
PromiseBase() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Throwable |
exceptSync()
Calling this method will block until the promise is resolved, returning a value if it resolved with
REJECTED, otherwise returning null. |
protected PromiseBase<T> |
fulfill(T value) |
protected java.lang.Throwable |
getException() |
PromiseState |
getState()
Get the current state of the promise.
|
protected T |
getValue() |
protected PromiseBase<T> |
reject(java.lang.Throwable exception) |
protected PromiseBase<T> |
resolve(Promise<? extends T> promise)
Resolve this promise with the same value/exception and state as another promise.
|
void |
sync()
Calling this method will block the current thread until
this is resolved (not PENDING). |
T |
thenSync()
Calling this method will block until the promise is resolved, returning a value if it resolved with
FULFILLED, otherwise returning null. |
protected final java.lang.Object lock
This used to be another object instanced by the constructor, but it has been changed to this, for now, since there is not any real need for a separate lock object.
public PromiseState getState()
Promise
A promise's initial state is PENDING, will change at most once, to either resolved states,
FULFILLED or REJECTED.
protected T getValue()
protected java.lang.Throwable getException()
protected PromiseBase<T> reject(java.lang.Throwable exception) throws MutatedStateException, java.lang.NullPointerException
MutatedStateExceptionjava.lang.NullPointerExceptionprotected PromiseBase<T> fulfill(T value) throws SelfResolutionException, MutatedStateException
protected PromiseBase<T> resolve(Promise<? extends T> promise) throws SelfResolutionException, MutatedStateException
Note that this may happen asynchronously, subsequent calls to resolve may fail silently. Take this into consideration especially if exposing this method externally.
Circular references are not checked, but we do take care not to directly resolve this.
promise - The promise to resolve.SelfResolutionException - If promise is this, or the promise is resolved to this.MutatedStateException - If this was already resolved, at the time of this call. Not triggered immediately if promise is PENDING.public void sync()
Promisethis is resolved (not PENDING).
All responsibility for sane use of this method lies with the caller.
public T thenSync()
PromiseFULFILLED, otherwise returning null.thenSync in interface Promise<T>null if REJECTED.Promise.sync()public java.lang.Throwable exceptSync()
PromiseREJECTED, otherwise returning null.exceptSync in interface Promise<T>null if FULFILLED.Promise.sync()