public class Continuation<T>
extends java.lang.Object
Continuation
provides mechanisms for continuing subsequent, later work on a different
thread (either a handler thread or a worker thread) along with a contextual object that will
be present at such time. The latter is usually a consumer of some type, that will thus receive
the result of some computation with threading all taken care of neat and tidy.Modifier and Type | Class and Description |
---|---|
protected static class |
Continuation.Dispatcher<S> |
protected static class |
Continuation.ExecutorDispatcher<S> |
protected static class |
Continuation.HandlerDispatcher<S> |
protected static class |
Continuation.TrivialDispatcher<S> |
Modifier and Type | Field and Description |
---|---|
protected Continuation.Dispatcher<T> |
dispatcher |
static java.lang.String |
TAG |
protected T |
target |
Modifier | Constructor and Description |
---|---|
protected |
Continuation(T target) |
Modifier and Type | Method and Description |
---|---|
boolean |
canBorrowThread(java.lang.Thread thread)
Caller guarantees that they're on a typical utility 'worker' thread (in contrast to,
for example, the dedicated UI thread, or other threads on which work is dispatched
through a
Handler ). |
static <T> Continuation<T> |
create(java.util.concurrent.Executor executor,
T t) |
static <T> Continuation<T> |
create(Handler handler,
T t) |
protected Continuation<T> |
createExecutorDispatcher(java.util.concurrent.Executor threadPool) |
<U> Continuation<U> |
createForNewTarget(U newTarget)
Return a new continuation that dispatches to the same location but operates on a new
target instance of a possibly different target type.
|
protected Continuation<T> |
createHandlerDispatcher(Handler handler) |
static <T> Continuation<T> |
createTrivial(T t) |
protected Continuation<T> |
createTrivialDispatcher() |
void |
dispatch(ContinuationResult<? super T> consumer) |
void |
dispatchHere(ContinuationResult<? super T> consumer)
Note: be very careful in the use of
dispatchHere(ContinuationResult) , as it
can easily lead to unexpected deadlocks. |
Continuation.Dispatcher<T> |
getDispatcher() |
Handler |
getHandler() |
T |
getTarget() |
boolean |
isDispatchSynchronous()
When we dispatch this continuation, is it a synchronous, blocking call, one that
will be fully executed before the dispatch returns?
|
boolean |
isHandler() |
boolean |
isTrivial() |
protected Continuation<T> |
setDispatcher(Continuation.Dispatcher<T> dispatcher) |
public static final java.lang.String TAG
protected final T target
protected Continuation.Dispatcher<T> dispatcher
protected Continuation(T target)
public T getTarget()
public Continuation.Dispatcher<T> getDispatcher()
public static <T> Continuation<T> createTrivial(T t)
public static <T> Continuation<T> create(java.util.concurrent.Executor executor, T t)
public static <T> Continuation<T> create(Handler handler, T t)
public <U> Continuation<U> createForNewTarget(U newTarget)
public void dispatch(ContinuationResult<? super T> consumer)
public void dispatchHere(ContinuationResult<? super T> consumer)
dispatchHere(ContinuationResult)
, as it
can easily lead to unexpected deadlocks.public boolean isHandler()
public Handler getHandler()
public boolean isTrivial()
public boolean isDispatchSynchronous()
public boolean canBorrowThread(java.lang.Thread thread)
Handler
). Answer whether we are ok to dispatch here instead of wherever
we might usually dispatch. Caller must additionally assure themselves from their contextual
knowledge that taking advantage of this function will not lead to deadlocks that otherwise
would not occur.protected Continuation<T> createTrivialDispatcher()
protected Continuation<T> createHandlerDispatcher(Handler handler)
protected Continuation<T> createExecutorDispatcher(java.util.concurrent.Executor threadPool)
protected Continuation<T> setDispatcher(Continuation.Dispatcher<T> dispatcher)