Skip to content

Commit

Permalink
Throw TimeoutCancellationException instead of CancellationException o…
Browse files Browse the repository at this point in the history
…n negative timeout in withTimeout

Fixes #870
  • Loading branch information
qwwdfsad committed Dec 6, 2018
1 parent a5b6a33 commit 3c4168b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/kotlinx-coroutines-core-common/src/Timeout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlin.jvm.*
* @param timeMillis timeout time in milliseconds.
*/
public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineScope.() -> T): T {
if (timeMillis <= 0L) throw CancellationException("Timed out immediately")
if (timeMillis <= 0L) throw TimeoutCancellationException("Timed out immediately")
return suspendCoroutineUninterceptedOrReturn { uCont ->
setupTimeout(TimeoutCoroutine(timeMillis, uCont), block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class WithTimeoutTest : TestBase() {
expectUnreached()
"OK"
}
} catch (e: CancellationException) {
} catch (e: TimeoutCancellationException) {
assertEquals("Timed out immediately", e.message)
finish(2)
}
Expand Down

0 comments on commit 3c4168b

Please sign in to comment.