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

Use Instant instead of SystemTime #42

Closed
uazu opened this issue Mar 8, 2019 · 3 comments · Fixed by #79
Closed

Use Instant instead of SystemTime #42

uazu opened this issue Mar 8, 2019 · 3 comments · Fixed by #79

Comments

@uazu
Copy link

uazu commented Mar 8, 2019

Instant is intended to be used for timers. SystemTime can go backwards, e.g. if the system clock is adjusted. If the clock goes backwards, then everything relying on a timer would stop working until time catches up again (e.g. hours/days later). See the docs in the std lib.

@mkj
Copy link
Contributor

mkj commented Aug 23, 2019

Instant makes sense for delay or interval values. What about schedule_at_time, I guess that kind of has to be real-world clock?

https://github.com/riker-rs/riker/blob/master/src/system/timer.rs#L128 looks like it needs a distinction between jobs using Instant jobs, and jobs using SystemTime.

@uazu
Copy link
Author

uazu commented Aug 23, 2019

Personally I'd run everything on Instant time. How many tools actually need to schedule things by wall clock time? Perhaps only cron, or personal assistant / scheduling type tools. Also since SystemTime can go backwards, there is no way to reliably trigger on a particular time being reached. So if you need to use wall clock time, either you estimate how long before SystemTime will reach the desired time, and wait for that in terms of Instant time, or else if you really care about noticing when SystemTime changes unexpectedly, you'd need to poll it at intervals. Those few cases can be handled in application code, since the application knows what tradeoffs it is happy with.

@riemass
Copy link
Contributor

riemass commented Oct 15, 2019

Please review the PR. I introduces Instant to timer. The call interface stays the same.
One part I don't like so much is that by subtracting DateTime<Utc> types, std::time::duration::Duration is returned, and Instant uses the std::time::Duration for addition, so I had to convert to an integer type and back to Duration type. I could not find any other workaround. Should be safe enough.

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 a pull request may close this issue.

3 participants