-
Notifications
You must be signed in to change notification settings - Fork 102
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
Consider removing Clock.asTimeSource
#372
Comments
What's the purpose of it then? What can it do that Monotonic cannot? |
What's the purpose of what? |
Sorry, I meant what is the purpose of |
The purpose could be, for example, to define your own |
How is this issue linked to #382? Also, isn't the (wall) clock based Timesource more precise than the monotonic due to ntp syncs/monotonic pauses, see #164 (comment)? |
If we decide this function is useful after all, I think that it, too, should migrate to the stdlib.
Wall clocks are neither more nor less precise than
|
Unrelated to the discussion, but a note about something that made me curious:
Looks like this isn't actually what's going to happen with |
Not a public usage of this, but our project uses this for one reason. We have a cache class that is supposed to expire. When we store a value we also store a TimeMark with it to know whether the value has expired. That time mark comes from an object that implements Clock so that we can control time in tests to tests things like the cache expiration. I think the problem with Monotonic is that it doesn't have a good way to control time in tests. It could probably be made to do so, but I think it is not quite there. |
Did you try https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/-test-time-source/ ? What's missing from it? |
What about TestTimeSource? |
@dalewking However in production, do you use Monotonic time source or the one that is obtained from |
Just now getting back to this and we were not using Monotonic and now I agree that Clock.asTimeSource should go away. For a good discussion on the topic see: https://www.youtube.com/watch?v=i1wysckHg2o |
There are no known public usages of this function: https://grep.app/search?q=asTimeSource&words=true Also,
Clock.System.asTimeSource().measureTime { }
looks fairly benign, even though it doesn't do what you want, given that the system clock can jump in time by several minutes occasionally.The text was updated successfully, but these errors were encountered: