T
- The type of value represented by the Promise
produced by an instance of this
class.public class PromiseSource<T> extends Object
Promise
instances. Instances of
this class are produced with a reference to an AsyncScheduler
, which is used to invoke
continuations on the returned Promise
. By default, the current scheduler is captured
when calling the constructor.Constructor and Description |
---|
PromiseSource()
Creates an instance based on the current schedule as returned by AsyncSchedulers#current().
|
PromiseSource(AsyncScheduler scheduler)
Creates an instance based on the given scheduler.
|
Modifier and Type | Method and Description |
---|---|
net.tpky.mc.concurrent.AsyncStackTrace |
getCallerStackTrace()
for internal use
|
Promise<T> |
getPromise()
Returns the
Promise associated with this instance. |
AsyncResult<? extends T> |
getResult()
Returns the result this instance has been set to or null, if not in completed state yet.
|
boolean |
isCompleted()
Returns whether this instance and the returned
Promise are in completed state,
regardless of whether completed successfully or exceptionally. |
void |
setAsyncResult(AsyncResult<? extends T> result)
Completes the
Promise associated with this instance with the given AsyncResult . |
void |
setException(Exception e)
|
void |
setResult(T result)
Completes the
Promise associated with this instance with the given value. |
boolean |
trySetAsyncResult(AsyncResult<? extends T> result)
Tries to complete the
Promise associated with this instance with the given
AsyncResult . |
boolean |
trySetException(Exception e)
|
boolean |
trySetResult(T result)
Tries to complete the
Promise associated with this instance with the given
value. |
public PromiseSource()
public PromiseSource(AsyncScheduler scheduler)
scheduler
- public Promise<T> getPromise()
Promise
associated with this instance.Promise
associated with this instance.public boolean isCompleted()
Promise
are in completed state,
regardless of whether completed successfully or exceptionally.Promise
are in completed state.public void setResult(T result)
Promise
associated with this instance with the given value.
Throws if it has already been completed.result
- the result value the associated Promise
should be resolved to.IllegalStateException
- if already in completed state.public boolean trySetResult(T result)
Promise
associated with this instance with the given
value. Ignores the given value if already in completed state.public void setException(Exception e)
Promise
associated with this instance with the given
Exception
.
Throws if already in completed state.e
- the Exception
the associated Promise
should be resolved to.IllegalStateException
- if already in completed state.public boolean trySetException(Exception e)
public void setAsyncResult(AsyncResult<? extends T> result)
Promise
associated with this instance with the given AsyncResult
.
Throws if it has already been completed.result
- the async result the associated Promise
should be resolved to.IllegalStateException
- if already in completed state.public boolean trySetAsyncResult(AsyncResult<? extends T> result)
Promise
associated with this instance with the given
AsyncResult
. Ignores the given value if already in completed state.public net.tpky.mc.concurrent.AsyncStackTrace getCallerStackTrace()
public AsyncResult<? extends T> getResult()