public static class AffinityExecutor.Gate implements AffinityExecutor
An executor useful for unit tests: allows the current thread to block until a command arrives from another thread, which is then executed. Inbound closures/commands stack up until they are cleared by looping.
AffinityExecutor.DefaultImpls, AffinityExecutor.Gate, AffinityExecutor.ServiceAffinityExecutor
Constructor and Description |
---|
Gate(boolean alwaysQueue)
An executor useful for unit tests: allows the current thread to block until a command arrives from another
thread, which is then executed. Inbound closures/commands stack up until they are cleared by looping.
|
Gate()
An executor useful for unit tests: allows the current thread to block until a command arrives from another
thread, which is then executed. Inbound closures/commands stack up until they are cleared by looping.
|
Modifier and Type | Method and Description |
---|---|
void |
checkOnThread()
Throws an IllegalStateException if the current thread is not one of the threads this executor is backed by.
|
void |
execute(java.lang.Runnable command) |
void |
executeASAP(kotlin.jvm.functions.Function0<kotlin.Unit> runnable)
If isOnThread() then runnable is invoked immediately, otherwise the closure is queued onto the backing thread.
|
<T> T |
fetchFrom(kotlin.jvm.functions.Function0<? extends T> fetcher)
Runs the given function on the executor, blocking until the result is available. Be careful not to deadlock this
way! Make sure the executor can't possibly be waiting for the calling thread.
|
void |
flush()
Run the executor until there are no tasks pending and none executing.
|
int |
getTaskQueueSize() |
boolean |
isOnThread()
Returns true if the current thread is equal to the thread this executor is backed by.
|
void |
waitAndRun() |
checkOnThread, executeASAP, fetchFrom, flush, isOnThread
public Gate(boolean alwaysQueue)
An executor useful for unit tests: allows the current thread to block until a command arrives from another thread, which is then executed. Inbound closures/commands stack up until they are cleared by looping.
alwaysQueue
- If true, executeASAP will never short-circuit and will always queue up.public Gate()
An executor useful for unit tests: allows the current thread to block until a command arrives from another thread, which is then executed. Inbound closures/commands stack up until they are cleared by looping.
public boolean isOnThread()
Returns true if the current thread is equal to the thread this executor is backed by.
public void execute(java.lang.Runnable command)
public void waitAndRun()
public int getTaskQueueSize()
public void flush()
Run the executor until there are no tasks pending and none executing.
public void checkOnThread()
Throws an IllegalStateException if the current thread is not one of the threads this executor is backed by.
public void executeASAP(kotlin.jvm.functions.Function0<kotlin.Unit> runnable)
If isOnThread() then runnable is invoked immediately, otherwise the closure is queued onto the backing thread.
public <T> T fetchFrom(kotlin.jvm.functions.Function0<? extends T> fetcher)
Runs the given function on the executor, blocking until the result is available. Be careful not to deadlock this way! Make sure the executor can't possibly be waiting for the calling thread.