Skip to content

Conversation

dswij
Copy link
Member

@dswij dswij commented Sep 17, 2025

This PR refactors the usage of Timer::sleep_until with Timer::sleep.

sleep_until is a convenient method that is logically equivalent with sleep, but requires the use of std::time::Instant. This have some effect when downstream users rely on non-std Instant.

This commit refactors all usage of `Timer::sleep_until` with
`Timer::sleep`.

`sleep_until` is a convenient method that is logically equivalent with
`sleep`, but requires the use of `std::time::Instant`.  This have some effect when
downstream users rely on non-std `Instant`.
}

let deadline = Instant::now() + self.duration;
self.timer.reset(&mut sleep, deadline);
Copy link
Member

Choose a reason for hiding this comment

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

This call has the benefit of allowing implementors to reuse an allocated sleep, instead of allocating a new one...

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true. But I wonder if reuse instead of allocation has that much of an impact in practice.

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.

2 participants