saito_core/core/process/
keep_time.rs1use crate::core::defs::Timestamp;
2use std::sync::Arc;
3
4pub trait KeepTime {
8 fn get_timestamp_in_ms(&self) -> Timestamp;
9}
10
11#[derive(Clone)]
12pub struct Timer {
13 pub time_reader: Arc<dyn KeepTime + Sync + Send>,
14 pub hasten_multiplier: u64,
15 pub start_time: Timestamp,
16}
17
18impl Timer {
19 pub fn get_timestamp_in_ms(&self) -> Timestamp {
20 assert_ne!(
21 self.hasten_multiplier, 0,
22 "hasten multiplier should be positive"
23 );
24
25 let current_time = self.time_reader.get_timestamp_in_ms();
26
27 self.start_time + (current_time - self.start_time) * self.hasten_multiplier
28 }
29}