public class WeakTimeoutQueue
It provides ability to cancel jobs and schedule coroutine with timeout. Unlike regular withTimeout this implementation is never scheduling timer tasks but only checks for current time. This makes timeout measurement much cheaper and doesn't require any watchdog thread.
There are two limitations:
timeout period is fixed
job cancellation is not guaranteed if no new jobs scheduled
The last one limitation is generally unacceptable however in the particular use-case (closing IDLE connection) it is just fine as we really don't care about stalling IDLE connections if there are no more incoming
| Constructor and Description |
|---|
WeakTimeoutQueue(long timeoutMillis,
kotlin.jvm.functions.Function0<java.lang.Long> clock)
It provides ability to cancel jobs and schedule coroutine with timeout. Unlike regular withTimeout
this implementation is never scheduling timer tasks but only checks for current time. This makes timeout measurement
much cheaper and doesn't require any watchdog thread.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancel all registered timeouts
|
long |
getTimeoutMillis() |
void |
process()
Process and cancel all jobs that are timed out
|
WeakTimeoutQueue.Registration |
register(kotlinx.coroutines.Job job)
Register job in this queue. It will be cancelled if doesn't complete in time.
|
<T> java.lang.Object |
withTimeout(kotlin.jvm.functions.Function2<? super kotlinx.coroutines.CoroutineScope,? super kotlin.coroutines.experimental.Continuation<? super T>,? extends java.lang.Object> block,
kotlin.coroutines.experimental.Continuation<? super T> p)
Execute block and cancel if doesn't complete in time.
|
public WeakTimeoutQueue(long timeoutMillis,
kotlin.jvm.functions.Function0<java.lang.Long> clock)
It provides ability to cancel jobs and schedule coroutine with timeout. Unlike regular withTimeout this implementation is never scheduling timer tasks but only checks for current time. This makes timeout measurement much cheaper and doesn't require any watchdog thread.
There are two limitations:
timeout period is fixed
job cancellation is not guaranteed if no new jobs scheduled
The last one limitation is generally unacceptable however in the particular use-case (closing IDLE connection) it is just fine as we really don't care about stalling IDLE connections if there are no more incoming
public WeakTimeoutQueue.Registration register(kotlinx.coroutines.Job job)
Register job in this queue. It will be cancelled if doesn't complete in time.
public void cancel()
Cancel all registered timeouts
public void process()
Process and cancel all jobs that are timed out
public <T> java.lang.Object withTimeout(kotlin.jvm.functions.Function2<? super kotlinx.coroutines.CoroutineScope,? super kotlin.coroutines.experimental.Continuation<? super T>,? extends java.lang.Object> block,
kotlin.coroutines.experimental.Continuation<? super T> p)
Execute block and cancel if doesn't complete in time.
public long getTimeoutMillis()