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

Replace time crate with httpdate #4169

Merged
merged 1 commit into from
Oct 15, 2021
Merged

Replace time crate with httpdate #4169

merged 1 commit into from
Oct 15, 2021

Conversation

serprex
Copy link
Contributor

@serprex serprex commented Oct 13, 2021

httpdate is used by hyper/warp/headers,
& this addresses the time crate used here being 0.1 while latest time crate is 0.3

@Darksonn Darksonn added the A-examples Area: The examples label Oct 14, 2021
Comment on lines 268 to 272
let now = time::get_time();
if now >= cache.next_update {
cache.update(now);
if let Ok(since_last_update) = cache.last_update.elapsed() {
if since_last_update > Duration::from_secs(1) {
cache.update();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this would misbehave if the clock is moved backwards, though that was probably also the case previously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be resolved by using Instant for cache & SystemTime only for generating string

Copy link
Contributor

Choose a reason for hiding this comment

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

That would work. Another approach would be to always regenerate if the time has gone backwards.

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 see now that the goal of the cache isn't to cache the date for a second, but to cache the date for that particular second

Code updated to store unix second & refresh when second changes

httpdate is used by hyper/warp/headers,
& this addresses the time crate used here being 0.1 while latest time crate is 0.3
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks.

@Darksonn Darksonn merged commit d4848a9 into tokio-rs:master Oct 15, 2021
oliver-giersch pushed a commit to oliver-giersch/tokio that referenced this pull request Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-examples Area: The examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants