Skip to content

Commit

Permalink
Move the extracted function into impl Timer
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku authored and andreev-io committed Dec 17, 2021
1 parent 94dd2aa commit 2ee9455
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions little_raft/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ impl Timer {
pub fn new(timeout: Duration) -> Timer {
Timer {
timeout: timeout,
rx: get_timeout_channel(timeout),
rx: Timer::get_timeout_channel(timeout),
}
}

pub fn renew(&mut self) {
self.rx = get_timeout_channel(self.timeout);
self.rx = Timer::get_timeout_channel(self.timeout);
}

pub fn get_rx(&self) -> &Receiver<()> {
&self.rx
}
}

fn get_timeout_channel(timeout: Duration) -> Receiver<()> {
let (tx, rx) = bounded(1);
thread::spawn(move || {
thread::sleep(timeout);
let _ = tx.send(());
});
fn get_timeout_channel(timeout: Duration) -> Receiver<()> {
let (tx, rx) = bounded(1);
thread::spawn(move || {
thread::sleep(timeout);
let _ = tx.send(());
});

rx
}
rx
}
}

0 comments on commit 2ee9455

Please sign in to comment.