Skip to content

Commit 247479d

Browse files
committed
Update delay and withTimeout* documentation
Fixes #3373
1 parent 1fc01e7 commit 247479d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

kotlinx-coroutines-core/common/src/Delay.kt

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public suspend fun awaitCancellation(): Nothing = suspendCancellableCoroutine {}
9494

9595
/**
9696
* Delays coroutine for a given time without blocking a thread and resumes it after a specified time.
97+
* If the given [timeMillis] is non-positive, this function returns immediately.
9798
*
9899
* This suspending function is cancellable.
99100
* If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
@@ -120,6 +121,7 @@ public suspend fun delay(timeMillis: Long) {
120121

121122
/**
122123
* Delays coroutine for a given [duration] without blocking a thread and resumes it after the specified time.
124+
* If the given [duration] is non-positive, this function returns immediately.
123125
*
124126
* This suspending function is cancellable.
125127
* If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function

kotlinx-coroutines-core/common/src/Timeout.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import kotlin.time.*
1717
/**
1818
* Runs a given suspending [block] of code inside a coroutine with a specified [timeout][timeMillis] and throws
1919
* a [TimeoutCancellationException] if the timeout was exceeded.
20+
* If the given [timeMillis] is non-positive, [TimeoutCancellationException] is thrown immediately.
2021
*
2122
* The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
2223
* the cancellable suspending function inside the block throws a [TimeoutCancellationException].
@@ -25,8 +26,8 @@ import kotlin.time.*
2526
* Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
2627
*
2728
* **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
28-
* even right before the return from inside of the timeout [block]. Keep this in mind if you open or acquire some
29-
* resource inside the [block] that needs closing or release outside of the block.
29+
* even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
30+
* resource inside the [block] that needs closing or release outside the block.
3031
* See the
3132
* [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
3233
* section of the coroutines guide for details.
@@ -48,6 +49,7 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
4849
/**
4950
* Runs a given suspending [block] of code inside a coroutine with the specified [timeout] and throws
5051
* a [TimeoutCancellationException] if the timeout was exceeded.
52+
* If the given [timeout] is non-positive, [TimeoutCancellationException] is thrown immediately.
5153
*
5254
* The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
5355
* the cancellable suspending function inside the block throws a [TimeoutCancellationException].
@@ -56,8 +58,8 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
5658
* Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
5759
*
5860
* **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
59-
* even right before the return from inside of the timeout [block]. Keep this in mind if you open or acquire some
60-
* resource inside the [block] that needs closing or release outside of the block.
61+
* even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
62+
* resource inside the [block] that needs closing or release outside the block.
6163
* See the
6264
* [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
6365
* section of the coroutines guide for details.
@@ -74,6 +76,7 @@ public suspend fun <T> withTimeout(timeout: Duration, block: suspend CoroutineSc
7476
/**
7577
* Runs a given suspending block of code inside a coroutine with a specified [timeout][timeMillis] and returns
7678
* `null` if this timeout was exceeded.
79+
* If the given [timeMillis] is non-positive, `null` is returned immediately.
7780
*
7881
* The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
7982
* cancellable suspending function inside the block throws a [TimeoutCancellationException].
@@ -82,8 +85,8 @@ public suspend fun <T> withTimeout(timeout: Duration, block: suspend CoroutineSc
8285
* Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
8386
*
8487
* **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
85-
* even right before the return from inside of the timeout [block]. Keep this in mind if you open or acquire some
86-
* resource inside the [block] that needs closing or release outside of the block.
88+
* even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
89+
* resource inside the [block] that needs closing or release outside the block.
8790
* See the
8891
* [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
8992
* section of the coroutines guide for details.
@@ -114,6 +117,7 @@ public suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend Corout
114117
/**
115118
* Runs a given suspending block of code inside a coroutine with the specified [timeout] and returns
116119
* `null` if this timeout was exceeded.
120+
* If the given [timeout] is non-positive, `null` is returned immediately.
117121
*
118122
* The code that is executing inside the [block] is cancelled on timeout and the active or next invocation of
119123
* cancellable suspending function inside the block throws a [TimeoutCancellationException].
@@ -122,8 +126,8 @@ public suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend Corout
122126
* Note that the timeout action can be specified for a [select] invocation with [onTimeout][SelectBuilder.onTimeout] clause.
123127
*
124128
* **The timeout event is asynchronous with respect to the code running in the block** and may happen at any time,
125-
* even right before the return from inside of the timeout [block]. Keep this in mind if you open or acquire some
126-
* resource inside the [block] that needs closing or release outside of the block.
129+
* even right before the return from inside the timeout [block]. Keep this in mind if you open or acquire some
130+
* resource inside the [block] that needs closing or release outside the block.
127131
* See the
128132
* [Asynchronous timeout and resources][https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources]
129133
* section of the coroutines guide for details.
@@ -177,7 +181,6 @@ public class TimeoutCancellationException internal constructor(
177181
TimeoutCancellationException(message ?: "", coroutine).also { it.initCause(this) }
178182
}
179183

180-
@Suppress("FunctionName")
181184
internal fun TimeoutCancellationException(
182185
time: Long,
183186
coroutine: Job

0 commit comments

Comments
 (0)