You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use Duration as the ground truth for communicating durations
Historically, the library evolved using "a Long of milliseconds"
as the standard of denoting durations.
Since then, `kotlin.time.Duration` appeared, encompassing a number
of useful conversions.
There are several consequences to this change.
- Before, `delay(Long)` and `delay(Duration)` were not easily
expressed via one another.
For example, `delay(Long.MAX_VALUE / 2 + 1)`
(up until `Long.MAX_VALUE`) used to be considered a valid
delay, but it was not expressible in `delay(Duration)`.
Therefore, `delay(Long)` was the more fundamental implementation.
However, `delay(Duration)` could not just be expressed as
`delay(inWholeMilliseconds)`, as we need to round the durations
up when delaying events, and this required complex logic.
With this change, `delay(Duration)` is taken as the standard
implementation, and `delay(Long)` is just
`delay(timeMillis.milliseconds)`, simplifying the conceptual
space.
- The same goes for other APIs accepting either a duration or
some Long number of milliseconds.
- In several platform APIs, we are actually able to
pass nanoseconds as the duration to wait for.
We can now accurately do that. This precision is unlikely to
be important in practice, but it is still nice that we are
not losing any information in transit.
- On Android's main thread, it's no longer possible to wait for
`Long.MAX_VALUE / 2` milliseconds: it's considered an infinite
duration.
`Long.MAX_VALUE / 2 - 1` is still fine.
- In `kotlinx-coroutines-test`, before, it was possible to
observe correct behavior for up to `Long.MAX_VALUE` milliseconds.
Now, this value is drastically reduced, to be able to test
the nanosecond precision.
- In `kotlinx-coroutines-test`, we now fail with
an `IllegalStateException` if we enter the
representable ceiling of time during the test.
Before, we used to continue the test execution, only using the
order in which tasks arrived but not their virtual time values.
Copy file name to clipboardExpand all lines: kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
+6-5
Original file line number
Diff line number
Diff line change
@@ -297,20 +297,21 @@ public final class kotlinx/coroutines/Deferred$DefaultImpls {
297
297
}
298
298
299
299
public abstract interface class kotlinx/coroutines/Delay {
300
-
public abstract fun delay (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
301
-
public abstract fun invokeOnTimeout (JLjava/lang/Runnable;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/DisposableHandle;
302
-
public abstract fun scheduleResumeAfterDelay (JLkotlinx/coroutines/CancellableContinuation;)V
300
+
public abstract fun invokeOnTimeout-KLykuaI (JLjava/lang/Runnable;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/DisposableHandle;
301
+
public abstract fun scheduleResumeAfterDelay-VtjQ1oo (JLkotlinx/coroutines/CancellableContinuation;)V
302
+
public abstract fun timeoutMessage-LRDsOJo (J)Ljava/lang/String;
303
303
}
304
304
305
305
public final class kotlinx/coroutines/Delay$DefaultImpls {
306
-
public static fun delay (Lkotlinx/coroutines/Delay;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
307
-
public static fun invokeOnTimeout (Lkotlinx/coroutines/Delay;JLjava/lang/Runnable;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/DisposableHandle;
306
+
public static fun invokeOnTimeout-KLykuaI (Lkotlinx/coroutines/Delay;JLjava/lang/Runnable;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/DisposableHandle;
307
+
public static fun timeoutMessage-LRDsOJo (Lkotlinx/coroutines/Delay;J)Ljava/lang/String;
308
308
}
309
309
310
310
public final class kotlinx/coroutines/DelayKt {
311
311
public static final fun awaitCancellation (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
312
312
public static final fun delay (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
313
313
public static final fun delay-VtjQ1oo (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
314
+
public static final fun toDelayMillis-LRDsOJo (J)J
314
315
}
315
316
316
317
public abstract interface annotation class kotlinx/coroutines/DelicateCoroutinesApi : java/lang/annotation/Annotation {
abstract fun scheduleResumeAfterDelay(kotlin/Long, kotlinx.coroutines/CancellableContinuation<kotlin/Unit>) // kotlinx.coroutines/Delay.scheduleResumeAfterDelay|scheduleResumeAfterDelay(kotlin.Long;kotlinx.coroutines.CancellableContinuation<kotlin.Unit>){}[0]
293
-
open fun invokeOnTimeout(kotlin/Long, kotlinx.coroutines/Runnable, kotlin.coroutines/CoroutineContext): kotlinx.coroutines/DisposableHandle // kotlinx.coroutines/Delay.invokeOnTimeout|invokeOnTimeout(kotlin.Long;kotlinx.coroutines.Runnable;kotlin.coroutines.CoroutineContext){}[0]
294
-
open suspend fun delay(kotlin/Long) // kotlinx.coroutines/Delay.delay|delay(kotlin.Long){}[0]
292
+
abstract fun scheduleResumeAfterDelay(kotlin.time/Duration, kotlinx.coroutines/CancellableContinuation<kotlin/Unit>) // kotlinx.coroutines/Delay.scheduleResumeAfterDelay|scheduleResumeAfterDelay(kotlin.time.Duration;kotlinx.coroutines.CancellableContinuation<kotlin.Unit>){}[0]
293
+
open fun invokeOnTimeout(kotlin.time/Duration, kotlinx.coroutines/Runnable, kotlin.coroutines/CoroutineContext): kotlinx.coroutines/DisposableHandle // kotlinx.coroutines/Delay.invokeOnTimeout|invokeOnTimeout(kotlin.time.Duration;kotlinx.coroutines.Runnable;kotlin.coroutines.CoroutineContext){}[0]
294
+
open fun timeoutMessage(kotlin.time/Duration): kotlin/String // kotlinx.coroutines/Delay.timeoutMessage|timeoutMessage(kotlin.time.Duration){}[0]
@@ -758,6 +758,7 @@ final fun (kotlin.coroutines/CoroutineContext).kotlinx.coroutines/ensureActive()
758
758
final fun (kotlin.coroutines/CoroutineContext).kotlinx.coroutines/newCoroutineContext(kotlin.coroutines/CoroutineContext): kotlin.coroutines/CoroutineContext // kotlinx.coroutines/newCoroutineContext|[email protected](kotlin.coroutines.CoroutineContext){}[0]
759
759
final fun (kotlin.ranges/IntRange).kotlinx.coroutines.flow/asFlow(): kotlinx.coroutines.flow/Flow<kotlin/Int> // kotlinx.coroutines.flow/asFlow|[email protected](){}[0]
760
760
final fun (kotlin.ranges/LongRange).kotlinx.coroutines.flow/asFlow(): kotlinx.coroutines.flow/Flow<kotlin/Long> // kotlinx.coroutines.flow/asFlow|[email protected](){}[0]
761
+
final fun (kotlin.time/Duration).kotlinx.coroutines/toDelayMillis(): kotlin/Long // kotlinx.coroutines/toDelayMillis|[email protected](){}[0]
761
762
final fun (kotlin/IntArray).kotlinx.coroutines.flow/asFlow(): kotlinx.coroutines.flow/Flow<kotlin/Int> // kotlinx.coroutines.flow/asFlow|[email protected](){}[0]
762
763
final fun (kotlin/LongArray).kotlinx.coroutines.flow/asFlow(): kotlinx.coroutines.flow/Flow<kotlin/Long> // kotlinx.coroutines.flow/asFlow|[email protected](){}[0]
763
764
final fun (kotlinx.coroutines.channels/ReceiveChannel<*>).kotlinx.coroutines.channels/cancelConsumed(kotlin/Throwable?) // kotlinx.coroutines.channels/cancelConsumed|[email protected]<*>(kotlin.Throwable?){}[0]
0 commit comments