-
Notifications
You must be signed in to change notification settings - Fork 67
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
Improve timer functionality #87
Conversation
src/lib.rs
Outdated
impl Default for Timer { | ||
fn default() -> Self { | ||
Timer::blank() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinions, but I personally feel it is a bit odd that a timer that is never resolved is the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three options I see are:
- Leave the
Timer
without aDefault
impl. - Have the default impl never fire.
- Have the default impl fire immediately.
Now that I think about it, the third options seems to be the least footgun-like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm starting to think that the first option is better. There aren't many instances where the Default
impl of a timer is called anyhow (unless you're storing them in a TinyVec
), and the ones where they would be feel unavoidably like a footgun. I'll just not have a Default
impl; we can discuss it later if we need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it seems better to postpone the Default
implementation until someone actually asks for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR fixes two outstanding issues with timers:
Timer
with large durations #86, where largeDuration
s can cause theTimer
code to panic as a result of unchecked addition. This PR checks to ensure that the addition does not overflow; if it does, it returns anInstant
in the far future.Timer
could exist that never fires. This not only adds ablank
method that creates a timer that isn't registered in theReactor
, but also uses this method to implementDefault
onTimer
.Closes #86
Closes #42