Skip to main content

reifydb_runtime/context/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4//! Sources of non-determinism the workspace consumes: the wall clock and the random number generator. Both have
5//! mockable variants so a deterministic-simulation run replaces them with seeded equivalents and reproduces the
6//! same trace bit-for-bit. Anything in the workspace that needs the time of day or a random value reaches for
7//! these handles instead of pulling from `std`.
8
9pub mod clock;
10pub mod rng;
11
12use clock::{Clock, MockClock};
13use rng::Rng;
14
15use crate::version_epoch::VersionEpoch;
16
17#[derive(Clone)]
18pub struct RuntimeContext {
19	pub clock: Clock,
20	pub rng: Rng,
21	pub version_epoch: VersionEpoch,
22}
23
24impl RuntimeContext {
25	pub fn new(clock: Clock, rng: Rng) -> Self {
26		Self {
27			clock,
28			rng,
29			version_epoch: VersionEpoch::new(),
30		}
31	}
32
33	pub fn with_clock(clock: Clock) -> Self {
34		Self {
35			clock,
36			rng: Rng::default(),
37			version_epoch: VersionEpoch::new(),
38		}
39	}
40
41	pub fn testing(initial_millis: u64, seed: u64) -> Self {
42		Self {
43			clock: Clock::Mock(MockClock::from_millis(initial_millis)),
44			rng: Rng::seeded(seed),
45			version_epoch: VersionEpoch::new(),
46		}
47	}
48}