Timeout

open class Timeout

A policy on how much time to spend on a task before giving up. When a task times out, it is left in an unspecified state and should be abandoned. For example, if reading from a source times out, that source should be closed and the read should be retried later. If writing to a sink times out, the same rules apply: close the sink and retry later.

Timeouts and Deadlines

This class offers two complementary controls to define a timeout policy.

Timeouts specify the maximum time to wait for a single operation to complete. Timeouts are typically used to detect problems like network partitions. For example, if a remote peer doesn't return any data for ten seconds, we may assume that the peer is unavailable.

Deadlines specify the maximum time to spend on a job, composed of one or more operations. Use deadlines to set an upper bound on the time invested on a job. For example, a battery-conscious app may limit how much time it spends pre-loading content.

open class Timeout

Types

Companion
Link copied to clipboard
common
object Companion

Functions

clearDeadline
Link copied to clipboard
open fun clearDeadline(): Timeout
Clears the deadline.
clearTimeout
Link copied to clipboard
open fun clearTimeout(): Timeout
Clears the timeout.
deadline
Link copied to clipboard
fun deadline(duration: Long, unit: TimeUnit): Timeout
Set a deadline of now plus duration time.
deadlineNanoTime
Link copied to clipboard
open fun deadlineNanoTime(): Long
Returns the nano time when the deadline will be reached.
open fun deadlineNanoTime(deadlineNanoTime: Long): Timeout
Sets the nano time when the deadline will be reached.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
open operator fun equals(other: Any?): Boolean
hasDeadline
Link copied to clipboard
open fun hasDeadline(): Boolean
Returns true if a deadline is enabled.
hashCode
Link copied to clipboard
open fun hashCode(): Int
open fun hashCode(): Int
intersectWith
Link copied to clipboard
inline fun intersectWith(other: Timeout, block: () -> Unit)
Applies the minimum intersection between this timeout and other, run block, then finally rollback this timeout's values.
throwIfReached
Link copied to clipboard
open fun throwIfReached()
Throws an InterruptedIOException if the deadline has been reached or if the current thread has been interrupted.
timeout
Link copied to clipboard
open fun timeout(timeout: Long, unit: TimeUnit): Timeout
Wait at most timeout time before aborting an operation.
timeoutNanos
Link copied to clipboard
open fun timeoutNanos(): Long
Returns the timeout in nanoseconds, or 0 for no timeout.
toString
Link copied to clipboard
open fun toString(): String
open fun toString(): String
waitUntilNotified
Link copied to clipboard
fun waitUntilNotified(monitor: Any)
Waits on monitor until it is notified.

Inheritors

AsyncTimeout
Link copied to clipboard
ForwardingTimeout
Link copied to clipboard