@@ -26,12 +26,12 @@ import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
26
26
27
27
/* *
28
28
* Runs a given suspending [block] of code inside a coroutine with a specified timeout and throws
29
- * [CancellationException ] if timeout was exceeded.
29
+ * [TimeoutException ] if timeout was exceeded.
30
30
*
31
31
* The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
32
- * cancellable suspending function inside the block throws [CancellationException ], so normally that exception,
32
+ * cancellable suspending function inside the block throws [TimeoutException ], so normally that exception,
33
33
* if uncaught, also gets thrown by `withTimeout` as a result.
34
- * However, the code in the block can suppress [CancellationException ].
34
+ * However, the code in the block can suppress [TimeoutException ].
35
35
*
36
36
* The sibling function that does not throw exception on timeout is [withTimeoutOrNull].
37
37
* Note, that timeout action can be specified for [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
@@ -74,9 +74,9 @@ private open class TimeoutCompletion<U, in T: U>(
74
74
* `null` if this timeout was exceeded.
75
75
*
76
76
* The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
77
- * cancellable suspending function inside the block throws [CancellationException ]. Normally that exception,
77
+ * cancellable suspending function inside the block throws [TimeoutException ]. Normally that exception,
78
78
* if uncaught by the block, gets converted into the `null` result of `withTimeoutOrNull`.
79
- * However, the code in the block can suppress [CancellationException ].
79
+ * However, the code in the block can suppress [TimeoutException ].
80
80
*
81
81
* The sibling function that throws exception on timeout is [withTimeout].
82
82
* Note, that timeout action can be specified for [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
@@ -120,8 +120,21 @@ private class TimeoutOrNullCompletion<T>(
120
120
}
121
121
}
122
122
123
- private class TimeoutException (
123
+ /* *
124
+ * This exception is thrown by [withTimeout] to indicate timeout.
125
+ */
126
+ public class TimeoutException internal constructor(
127
+ message : String ,
128
+ @JvmField internal val coroutine : Job ?
129
+ ) : CancellationException(message) {
130
+ /* *
131
+ * Creates timeout exception with a given message.
132
+ */
133
+ public constructor (message: String ) : this (message, null )
134
+ }
135
+
136
+ private fun TimeoutException (
124
137
time : Long ,
125
138
unit : TimeUnit ,
126
- @JvmField val coroutine : Job
127
- ) : CancellationException (" Timed out waiting for $time $unit " )
139
+ coroutine : Job
140
+ ) : TimeoutException = TimeoutException (" Timed out waiting for $time $unit " , coroutine )
0 commit comments