Use Duration as the ground truth for communicating durations #4256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
delay(Long)
anddelay(Duration)
were not easily expressed via one another. For example,delay(Long.MAX_VALUE / 2 + 1)
(up untilLong.MAX_VALUE
) used to be considered a valid delay, but it was not expressible indelay(Duration)
. Therefore,delay(Long)
was the more fundamental implementation. However,delay(Duration)
could not just be expressed asdelay(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, anddelay(Long)
is justdelay(timeMillis.milliseconds)
, simplifying the conceptual space.Long.MAX_VALUE / 2
milliseconds: it's considered an infinite duration.Long.MAX_VALUE / 2 - 1
is still fine.kotlinx-coroutines-test
, before, it was possible to observe correct behavior for up toLong.MAX_VALUE
milliseconds. Now, this value is drastically reduced, to be able to test the nanosecond precision.kotlinx-coroutines-test
, we now fail with anIllegalStateException
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.