Skip to content

Commit

Permalink
Reworked clock controller initialization to no longer require unwrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 authored and folkertdev committed Oct 26, 2023
1 parent 0840493 commit 54b2321
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ntpd/src/daemon/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,16 @@ impl<C: NtpClock, T: Wait> System<C, T> {
}

fn clock_controller(&mut self) -> Result<&mut KalmanClockController<C, PeerId>, C::Error> {
if self.controller.is_none() {
self.controller = Some(KalmanClockController::new(
let controller = match self.controller.take() {
Some(controller) => controller,
None => KalmanClockController::new(
self.clock.clone(),
self.synchronization_config,
self.peer_defaults_config,
self.synchronization_config.algorithm,
)?);
}
// Won't panic as the above if ensures controller contains something
Ok(self.controller.as_mut().unwrap())
)?,
};
Ok(self.controller.insert(controller))
}

fn add_spawner(
Expand Down

0 comments on commit 54b2321

Please sign in to comment.