Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly round Duration instances to milliseconds #3921

Merged

Conversation

kevincianfarini
Copy link
Contributor

@kevincianfarini kevincianfarini commented Oct 23, 2023

Prior to this commit Durations used for delays or timeouts lost their nanosecond granularity when being converted to a millisecond Long value. This effectively meant that delays could resume prior to when they were scheduled to do so.

This commit solves this by rounding a Duration with nanosecond components up to the next largest millisecond.

Closes #3920

@@ -133,7 +133,7 @@ public suspend fun delay(timeMillis: Long) {
}

/**
* Delays coroutine for a given [duration] without blocking a thread and resumes it after the specified time.
* Delays coroutine for at least the given [duration] without blocking a thread and resumes it after the specified time.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt that this was an important distinction which felt natural to make here. Please let me know if I should revert.

kotlinx-coroutines-core/common/src/Delay.kt Outdated Show resolved Hide resolved
kotlinx-coroutines-core/common/src/Delay.kt Outdated Show resolved Hide resolved
kotlinx-coroutines-core/common/src/Delay.kt Outdated Show resolved Hide resolved
kotlinx-coroutines-core/common/src/Delay.kt Outdated Show resolved Hide resolved
@kevincianfarini
Copy link
Contributor Author

Hi! If there's any other desired changes I'm happy to make them.

@dkhalanskyjb
Copy link
Contributor

Please rebase your changes on top of develop and set that as the base of the PR. See https://github.com/Kotlin/kotlinx.coroutines/blob/master/CONTRIBUTING.md#submitting-prs

Prior to this commit Durations used in for delays or timeouts
lost their nanosecond granularity when being converted to a
millisecond Long value. This effectively meant that delays could
resume prior to when they were scheduled to do so.

This commit solves this by rounding a Duration with nanosecond
components up to the next largest millisecond.

Closes Kotlin#3920
@kevincianfarini kevincianfarini changed the base branch from master to develop October 27, 2023 12:09
@kevincianfarini
Copy link
Contributor Author

Done. Sorry, I should have checked the contribution guide first.

@kevincianfarini
Copy link
Contributor Author

Do we think there's a chance this will be merged prior to the next version release? 😄

@dkhalanskyjb
Copy link
Contributor

Yes.

Copy link
Contributor

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:thumb-up:

@dkhalanskyjb dkhalanskyjb merged commit ff95ab7 into Kotlin:develop Nov 15, 2023
@kevincianfarini
Copy link
Contributor Author

Nice! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

delay(Duration) improperly coerces nanoseconds and microseconds
4 participants