forked from ihrwein/backoff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
tokio::time::Instant
in SystemClock
`tokio::time::Instant` is a special `Instant` type that supports mocking for tests (via [`tokio::time::pause`][pause]). Furthermore, it [avoids panics][panic] in `Instant` arithmetic. When using `tokio::time::Instant`, there's no need for a dependency on the `instant` crate. This change: * makes the `instant` crate an optional dependency, enabled by default; * uses `tokio::time::Instant` when the `tokio_1` feature is enabled and `instant` is not; and * uses `std::time::Instant` when neither of these features are enabled. The type is exposed publicly via `backoff::Instant` as a convenience. This change is backwards-compatible and does not change the default behavior. [pause]: https://docs.rs/tokio/latest/tokio/time/fn.pause.html [panic]: tokio-rs/tokio#4461 Signed-off-by: Oliver Gould <[email protected]>
- Loading branch information
Showing
8 changed files
with
20 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use instant::Instant; | ||
use crate::Instant; | ||
|
||
/// Clock returns the current time. | ||
pub trait Clock { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[cfg(feature = "instant")] | ||
pub use instant::Instant; | ||
|
||
#[cfg(all(feature = "tokio_1", not(feature = "instant")))] | ||
pub use tokio_1::time::Instant; | ||
|
||
#[cfg(not(any(feature = "tokio_1", feature = "instant")))] | ||
pub use std::time::Instant; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters