Skip to content

Commit 4d4d260

Browse files
authored
update quorum_ticks to use interval (#100)
1 parent 0c4ccf9 commit 4d4d260

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/lighthouse.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use structopt::StructOpt;
2626
use tokio::sync::broadcast;
2727
use tokio::sync::Mutex;
2828
use tokio::task::JoinSet;
29-
use tokio::time::sleep;
29+
use tokio::time::interval;
3030
use tonic::service::Routes;
3131
use tonic::transport::server::TcpIncoming;
3232
use tonic::transport::Server;
@@ -301,13 +301,11 @@ impl Lighthouse {
301301
}
302302

303303
async fn _run_quorum(self: Arc<Self>) -> Result<()> {
304+
let mut interval = interval(Duration::from_millis(self.opt.quorum_tick_ms));
304305
loop {
305-
{
306-
let mut state = self.state.lock().await;
307-
self.clone()._quorum_tick(&mut state)?;
308-
}
309-
310-
sleep(Duration::from_millis(self.opt.quorum_tick_ms)).await;
306+
interval.tick().await; // Wait for the next tick
307+
let mut state = self.state.lock().await;
308+
self.clone()._quorum_tick(&mut state)?;
311309
}
312310
}
313311

0 commit comments

Comments
 (0)