Skip to content

Commit ff9359a

Browse files
authored
Get rid of @ExperimentalTime where it is no longer necessary (#3041)
* Get rid of @ExperimentalTime where it is no longer necessary Fixes #3039
1 parent cf7b083 commit ff9359a

17 files changed

+70
-88
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ public suspend fun delay(timeMillis: Long) {
133133
*
134134
* Implementation note: how exactly time is tracked is an implementation detail of [CoroutineDispatcher] in the context.
135135
*/
136-
@ExperimentalTime
137136
public suspend fun delay(duration: Duration): Unit = delay(duration.toDelayMillis())
138137

139138
/** Returns [Delay] implementation of the given context */
@@ -143,6 +142,5 @@ internal val CoroutineContext.delay: Delay get() = get(ContinuationInterceptor)
143142
* Convert this duration to its millisecond value.
144143
* Positive durations are coerced at least `1`.
145144
*/
146-
@ExperimentalTime
147145
internal fun Duration.toDelayMillis(): Long =
148146
if (this > Duration.ZERO) inWholeMilliseconds.coerceAtLeast(1) else 0

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

-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
6464
*
6565
* > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
6666
*/
67-
@ExperimentalTime
6867
public suspend fun <T> withTimeout(timeout: Duration, block: suspend CoroutineScope.() -> T): T {
6968
contract {
7069
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
@@ -131,7 +130,6 @@ public suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend Corout
131130
*
132131
* > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
133132
*/
134-
@ExperimentalTime
135133
public suspend fun <T> withTimeoutOrNull(timeout: Duration, block: suspend CoroutineScope.() -> T): T? =
136134
withTimeoutOrNull(timeout.toDelayMillis(), block)
137135

kotlinx-coroutines-core/common/src/flow/SharingStarted.kt

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public fun interface SharingStarted {
135135
* are negative.
136136
*/
137137
@Suppress("FunctionName")
138-
@ExperimentalTime
139138
public fun SharingStarted.Companion.WhileSubscribed(
140139
stopTimeout: Duration = Duration.ZERO,
141140
replayExpiration: Duration = Duration.INFINITE

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

-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import kotlin.time.*
1717
/* Scaffolding for Knit code examples
1818
<!--- TEST_NAME FlowDelayTest -->
1919
<!--- PREFIX .*-duration-.*
20-
@file:OptIn(ExperimentalTime::class)
2120
----- INCLUDE .*-duration-.*
2221
import kotlin.time.*
2322
----- INCLUDE .*
@@ -150,7 +149,6 @@ public fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T> =
150149
* Note that the resulting flow does not emit anything as long as the original flow emits
151150
* items faster than every [timeout] milliseconds.
152151
*/
153-
@ExperimentalTime
154152
@FlowPreview
155153
public fun <T> Flow<T>.debounce(timeout: Duration): Flow<T> =
156154
debounce(timeout.toDelayMillis())
@@ -197,7 +195,6 @@ public fun <T> Flow<T>.debounce(timeout: Duration): Flow<T> =
197195
*
198196
* @param timeout [T] is the emitted value and the return value is timeout in [Duration].
199197
*/
200-
@ExperimentalTime
201198
@FlowPreview
202199
@JvmName("debounceDuration")
203200
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@@ -346,6 +343,5 @@ internal fun CoroutineScope.fixedPeriodTicker(delayMillis: Long, initialDelayMil
346343
*
347344
* Note that the latest element is not emitted if it does not fit into the sampling window.
348345
*/
349-
@ExperimentalTime
350346
@FlowPreview
351347
public fun <T> Flow<T>.sample(period: Duration): Flow<T> = sample(period.toDelayMillis())

kotlinx-coroutines-core/common/src/selects/Select.kt

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public interface SelectBuilder<in R> {
6262
* **Note: This is an experimental api.** It may be replaced with light-weight timer/timeout channels in the future.
6363
*/
6464
@ExperimentalCoroutinesApi
65-
@ExperimentalTime
6665
public fun <R> SelectBuilder<R>.onTimeout(timeout: Duration, block: suspend () -> R): Unit =
6766
onTimeout(timeout.toDelayMillis(), block)
6867

kotlinx-coroutines-core/common/test/DelayDurationTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import kotlin.time.*
1313
import kotlin.time.Duration.Companion.seconds
1414
import kotlin.time.Duration.Companion.nanoseconds
1515

16-
@ExperimentalTime
1716
class DelayDurationTest : TestBase() {
1817

1918
@Test

kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt

+16-15
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ package kotlinx.coroutines
88

99
import kotlin.test.*
1010
import kotlin.time.*
11+
import kotlin.time.Duration.Companion.milliseconds
12+
import kotlin.time.Duration.Companion.seconds
1113

12-
@ExperimentalTime
1314
class WithTimeoutDurationTest : TestBase() {
1415
/**
1516
* Tests a case of no timeout and no suspension inside.
1617
*/
1718
@Test
1819
fun testBasicNoSuspend() = runTest {
1920
expect(1)
20-
val result = withTimeout(Duration.seconds(10)) {
21+
val result = withTimeout(10.seconds) {
2122
expect(2)
2223
"OK"
2324
}
@@ -31,7 +32,7 @@ class WithTimeoutDurationTest : TestBase() {
3132
@Test
3233
fun testBasicSuspend() = runTest {
3334
expect(1)
34-
val result = withTimeout(Duration.seconds(10)) {
35+
val result = withTimeout(10.seconds) {
3536
expect(2)
3637
yield()
3738
expect(3)
@@ -54,7 +55,7 @@ class WithTimeoutDurationTest : TestBase() {
5455
}
5556
expect(2)
5657
// test that it does not yield to the above job when started
57-
val result = withTimeout(Duration.seconds(1)) {
58+
val result = withTimeout(1.seconds) {
5859
expect(3)
5960
yield() // yield only now
6061
expect(5)
@@ -74,7 +75,7 @@ class WithTimeoutDurationTest : TestBase() {
7475
fun testYieldBlockingWithTimeout() = runTest(
7576
expected = { it is CancellationException }
7677
) {
77-
withTimeout(Duration.milliseconds(100)) {
78+
withTimeout(100.milliseconds) {
7879
while (true) {
7980
yield()
8081
}
@@ -87,7 +88,7 @@ class WithTimeoutDurationTest : TestBase() {
8788
@Test
8889
fun testWithTimeoutChildWait() = runTest {
8990
expect(1)
90-
withTimeout(Duration.milliseconds(100)) {
91+
withTimeout(100.milliseconds) {
9192
expect(2)
9293
// launch child with timeout
9394
launch {
@@ -102,7 +103,7 @@ class WithTimeoutDurationTest : TestBase() {
102103
@Test
103104
fun testBadClass() = runTest {
104105
val bad = BadClass()
105-
val result = withTimeout(Duration.milliseconds(100)) {
106+
val result = withTimeout(100.milliseconds) {
106107
bad
107108
}
108109
assertSame(bad, result)
@@ -118,9 +119,9 @@ class WithTimeoutDurationTest : TestBase() {
118119
fun testExceptionOnTimeout() = runTest {
119120
expect(1)
120121
try {
121-
withTimeout(Duration.milliseconds(100)) {
122+
withTimeout(100.milliseconds) {
122123
expect(2)
123-
delay(Duration.milliseconds(1000))
124+
delay(1000.milliseconds)
124125
expectUnreached()
125126
"OK"
126127
}
@@ -135,10 +136,10 @@ class WithTimeoutDurationTest : TestBase() {
135136
expected = { it is CancellationException }
136137
) {
137138
expect(1)
138-
withTimeout(Duration.milliseconds(100)) {
139+
withTimeout(100.milliseconds) {
139140
expect(2)
140141
try {
141-
delay(Duration.milliseconds(1000))
142+
delay(1000.milliseconds)
142143
} catch (e: CancellationException) {
143144
finish(3)
144145
}
@@ -151,10 +152,10 @@ class WithTimeoutDurationTest : TestBase() {
151152
fun testSuppressExceptionWithAnotherException() = runTest {
152153
expect(1)
153154
try {
154-
withTimeout(Duration.milliseconds(100)) {
155+
withTimeout(100.milliseconds) {
155156
expect(2)
156157
try {
157-
delay(Duration.milliseconds(1000))
158+
delay(1000.milliseconds)
158159
} catch (e: CancellationException) {
159160
expect(3)
160161
throw TestException()
@@ -172,7 +173,7 @@ class WithTimeoutDurationTest : TestBase() {
172173
fun testNegativeTimeout() = runTest {
173174
expect(1)
174175
try {
175-
withTimeout(-Duration.milliseconds(1)) {
176+
withTimeout(-1.milliseconds) {
176177
expectUnreached()
177178
"OK"
178179
}
@@ -187,7 +188,7 @@ class WithTimeoutDurationTest : TestBase() {
187188
expect(1)
188189
try {
189190
expect(2)
190-
withTimeout(Duration.seconds(1)) {
191+
withTimeout(1.seconds) {
191192
expect(3)
192193
throw TestException()
193194
}

kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt

+22-21
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ package kotlinx.coroutines
1010
import kotlinx.coroutines.channels.*
1111
import kotlin.test.*
1212
import kotlin.time.*
13+
import kotlin.time.Duration.Companion.milliseconds
14+
import kotlin.time.Duration.Companion.seconds
1315

14-
@ExperimentalTime
1516
class WithTimeoutOrNullDurationTest : TestBase() {
1617
/**
1718
* Tests a case of no timeout and no suspension inside.
1819
*/
1920
@Test
2021
fun testBasicNoSuspend() = runTest {
2122
expect(1)
22-
val result = withTimeoutOrNull(Duration.seconds(10)) {
23+
val result = withTimeoutOrNull(10.seconds) {
2324
expect(2)
2425
"OK"
2526
}
@@ -33,7 +34,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
3334
@Test
3435
fun testBasicSuspend() = runTest {
3536
expect(1)
36-
val result = withTimeoutOrNull(Duration.seconds(10)) {
37+
val result = withTimeoutOrNull(10.seconds) {
3738
expect(2)
3839
yield()
3940
expect(3)
@@ -56,7 +57,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
5657
}
5758
expect(2)
5859
// test that it does not yield to the above job when started
59-
val result = withTimeoutOrNull(Duration.seconds(1)) {
60+
val result = withTimeoutOrNull(1.seconds) {
6061
expect(3)
6162
yield() // yield only now
6263
expect(5)
@@ -74,7 +75,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
7475
@Test
7576
fun testYieldBlockingWithTimeout() = runTest {
7677
expect(1)
77-
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
78+
val result = withTimeoutOrNull(100.milliseconds) {
7879
while (true) {
7980
yield()
8081
}
@@ -86,7 +87,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
8687
@Test
8788
fun testSmallTimeout() = runTest {
8889
val channel = Channel<Int>(1)
89-
val value = withTimeoutOrNull(Duration.milliseconds(1)) {
90+
val value = withTimeoutOrNull(1.milliseconds) {
9091
channel.receive()
9192
}
9293
assertNull(value)
@@ -103,8 +104,8 @@ class WithTimeoutOrNullDurationTest : TestBase() {
103104
fun testInnerTimeout() = runTest(
104105
expected = { it is CancellationException }
105106
) {
106-
withTimeoutOrNull(Duration.milliseconds(1000)) {
107-
withTimeout(Duration.milliseconds(10)) {
107+
withTimeoutOrNull(1000.milliseconds) {
108+
withTimeout(10.milliseconds) {
108109
while (true) {
109110
yield()
110111
}
@@ -119,7 +120,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
119120
fun testNestedTimeout() = runTest(expected = { it is TimeoutCancellationException }) {
120121
withTimeoutOrNull(Duration.INFINITE) {
121122
// Exception from this withTimeout is not suppressed by withTimeoutOrNull
122-
withTimeout(Duration.milliseconds(10)) {
123+
withTimeout(10.milliseconds) {
123124
delay(Duration.INFINITE)
124125
1
125126
}
@@ -131,9 +132,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
131132
@Test
132133
fun testOuterTimeout() = runTest {
133134
var counter = 0
134-
val result = withTimeoutOrNull(Duration.milliseconds(250)) {
135+
val result = withTimeoutOrNull(250.milliseconds) {
135136
while (true) {
136-
val inner = withTimeoutOrNull(Duration.milliseconds(100)) {
137+
val inner = withTimeoutOrNull(100.milliseconds) {
137138
while (true) {
138139
yield()
139140
}
@@ -149,7 +150,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
149150
@Test
150151
fun testBadClass() = runTest {
151152
val bad = BadClass()
152-
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
153+
val result = withTimeoutOrNull(100.milliseconds) {
153154
bad
154155
}
155156
assertSame(bad, result)
@@ -164,9 +165,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
164165
@Test
165166
fun testNullOnTimeout() = runTest {
166167
expect(1)
167-
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
168+
val result = withTimeoutOrNull(100.milliseconds) {
168169
expect(2)
169-
delay(Duration.milliseconds(1000))
170+
delay(1000.milliseconds)
170171
expectUnreached()
171172
"OK"
172173
}
@@ -177,10 +178,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
177178
@Test
178179
fun testSuppressExceptionWithResult() = runTest {
179180
expect(1)
180-
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
181+
val result = withTimeoutOrNull(100.milliseconds) {
181182
expect(2)
182183
try {
183-
delay(Duration.milliseconds(1000))
184+
delay(1000.milliseconds)
184185
} catch (e: CancellationException) {
185186
expect(3)
186187
}
@@ -194,10 +195,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
194195
fun testSuppressExceptionWithAnotherException() = runTest {
195196
expect(1)
196197
try {
197-
withTimeoutOrNull(Duration.milliseconds(100)) {
198+
withTimeoutOrNull(100.milliseconds) {
198199
expect(2)
199200
try {
200-
delay(Duration.milliseconds(1000))
201+
delay(1000.milliseconds)
201202
} catch (e: CancellationException) {
202203
expect(3)
203204
throw TestException()
@@ -216,11 +217,11 @@ class WithTimeoutOrNullDurationTest : TestBase() {
216217
@Test
217218
fun testNegativeTimeout() = runTest {
218219
expect(1)
219-
var result = withTimeoutOrNull(-Duration.milliseconds(1)) {
220+
var result = withTimeoutOrNull(-1.milliseconds) {
220221
expectUnreached()
221222
}
222223
assertNull(result)
223-
result = withTimeoutOrNull(Duration.milliseconds(0)) {
224+
result = withTimeoutOrNull(0.milliseconds) {
224225
expectUnreached()
225226
}
226227
assertNull(result)
@@ -232,7 +233,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
232233
expect(1)
233234
try {
234235
expect(2)
235-
withTimeoutOrNull<Unit>(Duration.milliseconds(1000)) {
236+
withTimeoutOrNull<Unit>(1000.milliseconds) {
236237
expect(3)
237238
throw TestException()
238239
}

0 commit comments

Comments
 (0)