Skip to content

Commit

Permalink
refactor: change u64 to Duration (#636)
Browse files Browse the repository at this point in the history
* refactor: change poll_interval and all dependent lines of code.

* fix: broken test
  • Loading branch information
EmperorOrokuSaki authored Apr 25, 2024
1 parent 4d77029 commit f3528d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions crates/provider/src/heart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ impl<'a, T: Transport + Clone, N: Network> PendingTransactionBuilder<'a, T, N> {

// FIXME: this is a hotfix to prevent a race condition where the heartbeat would miss the
// block the tx was mined in
let mut interval =
tokio::time::interval(Duration::from_millis(self.provider.client().poll_interval()));
let mut interval = tokio::time::interval(self.provider.client().poll_interval());

loop {
let mut confirmed = false;
Expand Down
7 changes: 4 additions & 3 deletions crates/rpc-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
atomic::{AtomicU64, Ordering},
Arc, Weak,
},
time::Duration,
};
use tower::{layer::util::Identity, ServiceBuilder};

Expand Down Expand Up @@ -180,8 +181,8 @@ impl<T> RpcClientInner<T> {
}

/// Returns the default poll interval (milliseconds) for the client.
pub fn poll_interval(&self) -> u64 {
self.poll_interval.load(Ordering::Relaxed)
pub fn poll_interval(&self) -> Duration {
Duration::from_millis(self.poll_interval.load(Ordering::Relaxed))
}

/// Set the poll interval for the client in milliseconds.
Expand Down Expand Up @@ -346,6 +347,6 @@ mod tests {
let client = RpcClient::new_http(reqwest::Url::parse("http://localhost").unwrap())
.with_poll_interval(5000);
// let client = client;
assert_eq!(client.poll_interval(), 5000);
assert_eq!(client.poll_interval(), Duration::from_millis(5000));
}
}
5 changes: 2 additions & 3 deletions crates/rpc-client/src/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ where
method: impl Into<Cow<'static, str>>,
params: Params,
) -> Self {
let poll_interval = client
.upgrade()
.map_or_else(|| Duration::from_secs(7), |c| Duration::from_millis(c.poll_interval()));
let poll_interval =
client.upgrade().map_or_else(|| Duration::from_secs(7), |c| c.poll_interval());
Self {
client,
method: method.into(),
Expand Down

0 comments on commit f3528d5

Please sign in to comment.