Skip to content

Commit 87920c9

Browse files
committed
Made public class TimeoutException
Fixes #89
1 parent 0163bf1 commit 87920c9

File tree

1 file changed

+21
-8
lines changed
  • kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental

1 file changed

+21
-8
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Scheduled.kt

+21-8
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
2626

2727
/**
2828
* 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.
3030
*
3131
* 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,
3333
* 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].
3535
*
3636
* The sibling function that does not throw exception on timeout is [withTimeoutOrNull].
3737
* 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>(
7474
* `null` if this timeout was exceeded.
7575
*
7676
* 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,
7878
* 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].
8080
*
8181
* The sibling function that throws exception on timeout is [withTimeout].
8282
* Note, that timeout action can be specified for [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
@@ -120,8 +120,21 @@ private class TimeoutOrNullCompletion<T>(
120120
}
121121
}
122122

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(
124137
time: Long,
125138
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

Comments
 (0)