Skip to main content

Module clock

Module clock 

Source
Expand description

The time source the runtime reads, so that time is an input you control.

Every decision the runtime makes from elapsed time reads a Clock:

  • temporal patterns (“sustained for 5 s”);
  • phase durations;
  • resolver cache expiry;
  • the session: timing signals (silence_ms, elapsed_ms, …);
  • mutation-journal timestamps.

In production that is the SystemClock. In a test or a replay it is a ManualClock you advance yourself, so the same inputs give the same decisions every run. replay_session drives one from the recorded frame timestamps.

The clock travels with State: every clone and delta view shares it, so a component that can read state can read the time without another parameter.

use std::sync::Arc;
use std::time::Duration;
use gemini_adk_rs::clock::{Clock, ManualClock};
use gemini_adk_rs::State;

let clock = Arc::new(ManualClock::new());
let state = State::new().with_clock(clock.clone());

let t0 = state.clock().now();
clock.advance(Duration::from_secs(5));
assert_eq!(state.clock().now() - t0, Duration::from_secs(5));

Structs§

ManualClock
A clock that moves only when told to.
SystemClock
The real clock: Instant::now and SystemTime::now.

Traits§

Clock
A source of monotonic and wall-clock time.

Functions§

system_clock
The default clock: a shared SystemClock.

Type Aliases§

SharedClock
A shared, dynamically dispatched clock.