Skip to content

Commit

Permalink
Get rid of @ExperimentalTime where it is no longer necessary (#3041)
Browse files Browse the repository at this point in the history
* Get rid of @ExperimentalTime where it is no longer necessary

Fixes #3039
  • Loading branch information
qwwdfsad committed Nov 25, 2021
1 parent cf7b083 commit ff9359a
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 88 deletions.
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/common/src/Delay.kt
Expand Up @@ -133,7 +133,6 @@ public suspend fun delay(timeMillis: Long) {
*
* Implementation note: how exactly time is tracked is an implementation detail of [CoroutineDispatcher] in the context.
*/
@ExperimentalTime
public suspend fun delay(duration: Duration): Unit = delay(duration.toDelayMillis())

/** Returns [Delay] implementation of the given context */
Expand All @@ -143,6 +142,5 @@ internal val CoroutineContext.delay: Delay get() = get(ContinuationInterceptor)
* Convert this duration to its millisecond value.
* Positive durations are coerced at least `1`.
*/
@ExperimentalTime
internal fun Duration.toDelayMillis(): Long =
if (this > Duration.ZERO) inWholeMilliseconds.coerceAtLeast(1) else 0
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/common/src/Timeout.kt
Expand Up @@ -64,7 +64,6 @@ public suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineSco
*
* > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
*/
@ExperimentalTime
public suspend fun <T> withTimeout(timeout: Duration, block: suspend CoroutineScope.() -> T): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
Expand Down Expand Up @@ -131,7 +130,6 @@ public suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend Corout
*
* > Implementation note: how the time is tracked exactly is an implementation detail of the context's [CoroutineDispatcher].
*/
@ExperimentalTime
public suspend fun <T> withTimeoutOrNull(timeout: Duration, block: suspend CoroutineScope.() -> T): T? =
withTimeoutOrNull(timeout.toDelayMillis(), block)

Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/common/src/flow/SharingStarted.kt
Expand Up @@ -135,7 +135,6 @@ public fun interface SharingStarted {
* are negative.
*/
@Suppress("FunctionName")
@ExperimentalTime
public fun SharingStarted.Companion.WhileSubscribed(
stopTimeout: Duration = Duration.ZERO,
replayExpiration: Duration = Duration.INFINITE
Expand Down
4 changes: 0 additions & 4 deletions kotlinx-coroutines-core/common/src/flow/operators/Delay.kt
Expand Up @@ -17,7 +17,6 @@ import kotlin.time.*
/* Scaffolding for Knit code examples
<!--- TEST_NAME FlowDelayTest -->
<!--- PREFIX .*-duration-.*
@file:OptIn(ExperimentalTime::class)
----- INCLUDE .*-duration-.*
import kotlin.time.*
----- INCLUDE .*
Expand Down Expand Up @@ -150,7 +149,6 @@ public fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T> =
* Note that the resulting flow does not emit anything as long as the original flow emits
* items faster than every [timeout] milliseconds.
*/
@ExperimentalTime
@FlowPreview
public fun <T> Flow<T>.debounce(timeout: Duration): Flow<T> =
debounce(timeout.toDelayMillis())
Expand Down Expand Up @@ -197,7 +195,6 @@ public fun <T> Flow<T>.debounce(timeout: Duration): Flow<T> =
*
* @param timeout [T] is the emitted value and the return value is timeout in [Duration].
*/
@ExperimentalTime
@FlowPreview
@JvmName("debounceDuration")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
Expand Down Expand Up @@ -346,6 +343,5 @@ internal fun CoroutineScope.fixedPeriodTicker(delayMillis: Long, initialDelayMil
*
* Note that the latest element is not emitted if it does not fit into the sampling window.
*/
@ExperimentalTime
@FlowPreview
public fun <T> Flow<T>.sample(period: Duration): Flow<T> = sample(period.toDelayMillis())
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/common/src/selects/Select.kt
Expand Up @@ -62,7 +62,6 @@ public interface SelectBuilder<in R> {
* **Note: This is an experimental api.** It may be replaced with light-weight timer/timeout channels in the future.
*/
@ExperimentalCoroutinesApi
@ExperimentalTime
public fun <R> SelectBuilder<R>.onTimeout(timeout: Duration, block: suspend () -> R): Unit =
onTimeout(timeout.toDelayMillis(), block)

Expand Down
1 change: 0 additions & 1 deletion kotlinx-coroutines-core/common/test/DelayDurationTest.kt
Expand Up @@ -13,7 +13,6 @@ import kotlin.time.*
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Duration.Companion.nanoseconds

@ExperimentalTime
class DelayDurationTest : TestBase() {

@Test
Expand Down
31 changes: 16 additions & 15 deletions kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt
Expand Up @@ -8,16 +8,17 @@ package kotlinx.coroutines

import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

@ExperimentalTime
class WithTimeoutDurationTest : TestBase() {
/**
* Tests a case of no timeout and no suspension inside.
*/
@Test
fun testBasicNoSuspend() = runTest {
expect(1)
val result = withTimeout(Duration.seconds(10)) {
val result = withTimeout(10.seconds) {
expect(2)
"OK"
}
Expand All @@ -31,7 +32,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testBasicSuspend() = runTest {
expect(1)
val result = withTimeout(Duration.seconds(10)) {
val result = withTimeout(10.seconds) {
expect(2)
yield()
expect(3)
Expand All @@ -54,7 +55,7 @@ class WithTimeoutDurationTest : TestBase() {
}
expect(2)
// test that it does not yield to the above job when started
val result = withTimeout(Duration.seconds(1)) {
val result = withTimeout(1.seconds) {
expect(3)
yield() // yield only now
expect(5)
Expand All @@ -74,7 +75,7 @@ class WithTimeoutDurationTest : TestBase() {
fun testYieldBlockingWithTimeout() = runTest(
expected = { it is CancellationException }
) {
withTimeout(Duration.milliseconds(100)) {
withTimeout(100.milliseconds) {
while (true) {
yield()
}
Expand All @@ -87,7 +88,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testWithTimeoutChildWait() = runTest {
expect(1)
withTimeout(Duration.milliseconds(100)) {
withTimeout(100.milliseconds) {
expect(2)
// launch child with timeout
launch {
Expand All @@ -102,7 +103,7 @@ class WithTimeoutDurationTest : TestBase() {
@Test
fun testBadClass() = runTest {
val bad = BadClass()
val result = withTimeout(Duration.milliseconds(100)) {
val result = withTimeout(100.milliseconds) {
bad
}
assertSame(bad, result)
Expand All @@ -118,9 +119,9 @@ class WithTimeoutDurationTest : TestBase() {
fun testExceptionOnTimeout() = runTest {
expect(1)
try {
withTimeout(Duration.milliseconds(100)) {
withTimeout(100.milliseconds) {
expect(2)
delay(Duration.milliseconds(1000))
delay(1000.milliseconds)
expectUnreached()
"OK"
}
Expand All @@ -135,10 +136,10 @@ class WithTimeoutDurationTest : TestBase() {
expected = { it is CancellationException }
) {
expect(1)
withTimeout(Duration.milliseconds(100)) {
withTimeout(100.milliseconds) {
expect(2)
try {
delay(Duration.milliseconds(1000))
delay(1000.milliseconds)
} catch (e: CancellationException) {
finish(3)
}
Expand All @@ -151,10 +152,10 @@ class WithTimeoutDurationTest : TestBase() {
fun testSuppressExceptionWithAnotherException() = runTest {
expect(1)
try {
withTimeout(Duration.milliseconds(100)) {
withTimeout(100.milliseconds) {
expect(2)
try {
delay(Duration.milliseconds(1000))
delay(1000.milliseconds)
} catch (e: CancellationException) {
expect(3)
throw TestException()
Expand All @@ -172,7 +173,7 @@ class WithTimeoutDurationTest : TestBase() {
fun testNegativeTimeout() = runTest {
expect(1)
try {
withTimeout(-Duration.milliseconds(1)) {
withTimeout(-1.milliseconds) {
expectUnreached()
"OK"
}
Expand All @@ -187,7 +188,7 @@ class WithTimeoutDurationTest : TestBase() {
expect(1)
try {
expect(2)
withTimeout(Duration.seconds(1)) {
withTimeout(1.seconds) {
expect(3)
throw TestException()
}
Expand Down
Expand Up @@ -10,16 +10,17 @@ package kotlinx.coroutines
import kotlinx.coroutines.channels.*
import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

@ExperimentalTime
class WithTimeoutOrNullDurationTest : TestBase() {
/**
* Tests a case of no timeout and no suspension inside.
*/
@Test
fun testBasicNoSuspend() = runTest {
expect(1)
val result = withTimeoutOrNull(Duration.seconds(10)) {
val result = withTimeoutOrNull(10.seconds) {
expect(2)
"OK"
}
Expand All @@ -33,7 +34,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testBasicSuspend() = runTest {
expect(1)
val result = withTimeoutOrNull(Duration.seconds(10)) {
val result = withTimeoutOrNull(10.seconds) {
expect(2)
yield()
expect(3)
Expand All @@ -56,7 +57,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
}
expect(2)
// test that it does not yield to the above job when started
val result = withTimeoutOrNull(Duration.seconds(1)) {
val result = withTimeoutOrNull(1.seconds) {
expect(3)
yield() // yield only now
expect(5)
Expand All @@ -74,7 +75,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testYieldBlockingWithTimeout() = runTest {
expect(1)
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
val result = withTimeoutOrNull(100.milliseconds) {
while (true) {
yield()
}
Expand All @@ -86,7 +87,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testSmallTimeout() = runTest {
val channel = Channel<Int>(1)
val value = withTimeoutOrNull(Duration.milliseconds(1)) {
val value = withTimeoutOrNull(1.milliseconds) {
channel.receive()
}
assertNull(value)
Expand All @@ -103,8 +104,8 @@ class WithTimeoutOrNullDurationTest : TestBase() {
fun testInnerTimeout() = runTest(
expected = { it is CancellationException }
) {
withTimeoutOrNull(Duration.milliseconds(1000)) {
withTimeout(Duration.milliseconds(10)) {
withTimeoutOrNull(1000.milliseconds) {
withTimeout(10.milliseconds) {
while (true) {
yield()
}
Expand All @@ -119,7 +120,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
fun testNestedTimeout() = runTest(expected = { it is TimeoutCancellationException }) {
withTimeoutOrNull(Duration.INFINITE) {
// Exception from this withTimeout is not suppressed by withTimeoutOrNull
withTimeout(Duration.milliseconds(10)) {
withTimeout(10.milliseconds) {
delay(Duration.INFINITE)
1
}
Expand All @@ -131,9 +132,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testOuterTimeout() = runTest {
var counter = 0
val result = withTimeoutOrNull(Duration.milliseconds(250)) {
val result = withTimeoutOrNull(250.milliseconds) {
while (true) {
val inner = withTimeoutOrNull(Duration.milliseconds(100)) {
val inner = withTimeoutOrNull(100.milliseconds) {
while (true) {
yield()
}
Expand All @@ -149,7 +150,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testBadClass() = runTest {
val bad = BadClass()
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
val result = withTimeoutOrNull(100.milliseconds) {
bad
}
assertSame(bad, result)
Expand All @@ -164,9 +165,9 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testNullOnTimeout() = runTest {
expect(1)
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
val result = withTimeoutOrNull(100.milliseconds) {
expect(2)
delay(Duration.milliseconds(1000))
delay(1000.milliseconds)
expectUnreached()
"OK"
}
Expand All @@ -177,10 +178,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testSuppressExceptionWithResult() = runTest {
expect(1)
val result = withTimeoutOrNull(Duration.milliseconds(100)) {
val result = withTimeoutOrNull(100.milliseconds) {
expect(2)
try {
delay(Duration.milliseconds(1000))
delay(1000.milliseconds)
} catch (e: CancellationException) {
expect(3)
}
Expand All @@ -194,10 +195,10 @@ class WithTimeoutOrNullDurationTest : TestBase() {
fun testSuppressExceptionWithAnotherException() = runTest {
expect(1)
try {
withTimeoutOrNull(Duration.milliseconds(100)) {
withTimeoutOrNull(100.milliseconds) {
expect(2)
try {
delay(Duration.milliseconds(1000))
delay(1000.milliseconds)
} catch (e: CancellationException) {
expect(3)
throw TestException()
Expand All @@ -216,11 +217,11 @@ class WithTimeoutOrNullDurationTest : TestBase() {
@Test
fun testNegativeTimeout() = runTest {
expect(1)
var result = withTimeoutOrNull(-Duration.milliseconds(1)) {
var result = withTimeoutOrNull(-1.milliseconds) {
expectUnreached()
}
assertNull(result)
result = withTimeoutOrNull(Duration.milliseconds(0)) {
result = withTimeoutOrNull(0.milliseconds) {
expectUnreached()
}
assertNull(result)
Expand All @@ -232,7 +233,7 @@ class WithTimeoutOrNullDurationTest : TestBase() {
expect(1)
try {
expect(2)
withTimeoutOrNull<Unit>(Duration.milliseconds(1000)) {
withTimeoutOrNull<Unit>(1000.milliseconds) {
expect(3)
throw TestException()
}
Expand Down

0 comments on commit ff9359a

Please sign in to comment.