use chrono::{DateTime, Utc};
use std::{sync::Arc, time::Duration};
use super::manual::ManualClock;
#[derive(Clone)]
pub struct ClockController {
pub(crate) clock: Arc<ManualClock>,
}
impl ClockController {
pub async fn advance(&self, duration: Duration) -> usize {
self.clock.advance(duration).await
}
pub async fn advance_to_next_wake(&self) -> Option<DateTime<Utc>> {
self.clock.advance_to_next_wake().await
}
pub fn pending_wake_count(&self) -> usize {
self.clock.pending_wake_count()
}
pub fn now(&self) -> DateTime<Utc> {
self.clock.now()
}
}
impl std::fmt::Debug for ClockController {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ClockController")
.field("now", &self.clock.now())
.field("pending_wakes", &self.clock.pending_wake_count())
.finish()
}
}