public class TimeoutKt
Modifier and Type | Method and Description |
---|---|
static <T> java.lang.Object |
withTimeout(long timeMillis,
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)
Runs a given suspending block of code inside a coroutine with a specified timeout and throws
exception TimeoutCancellationException if timeout was exceeded. |
static <T> java.lang.Object |
withTimeoutOrNull(long timeMillis,
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)
Runs a given suspending block of code inside a coroutine with a specified timeout and returns
null if this timeout was exceeded. |
public static <T> java.lang.Object withTimeout(long timeMillis, 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)
Runs a given suspending block of code inside a coroutine with a specified timeout and throws
exception TimeoutCancellationException
if timeout was exceeded.
The code that is executing inside the block is cancelled on timeout and the active or next invocation of
cancellable suspending function inside the block throws exception TimeoutCancellationException
.
The sibling function that does not throw exception on timeout is TimeoutKt.withTimeoutOrNull
.
Note, that timeout action can be specified for select invocation with SelectBuilder.onTimeout
clause.
Implementation note: how exactly time is tracked is an implementation detail of class CoroutineDispatcher
in the context.
timeMillis
- timeout time in milliseconds.exception TimeoutCancellationException
,
exception TimeoutCancellationException
,
TimeoutKt.withTimeoutOrNull
,
SelectBuilder.onTimeout
,
class CoroutineDispatcher
public static <T> java.lang.Object withTimeoutOrNull(long timeMillis, 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)
Runs a given suspending block of code inside a coroutine with a specified timeout and returns
null
if this timeout was exceeded.
The code that is executing inside the block is cancelled on timeout and the active or next invocation of
cancellable suspending function inside the block throws exception TimeoutCancellationException
.
The sibling function that throws exception on timeout is TimeoutKt.withTimeout
.
Note, that timeout action can be specified for select invocation with SelectBuilder.onTimeout
clause.
Implementation note: how exactly time is tracked is an implementation detail of class CoroutineDispatcher
in the context.
timeMillis
- timeout time in milliseconds.exception TimeoutCancellationException
,
TimeoutKt.withTimeout
,
SelectBuilder.onTimeout
,
class CoroutineDispatcher