Skip to main content

reifydb_runtime/context/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Runtime context that bundles clock and RNG for the execution engine.
5
6pub mod clock;
7pub mod rng;
8
9use clock::{Clock, MockClock};
10use rng::Rng;
11
12/// A container for runtime services (clock, RNG) threaded through the execution engine.
13#[derive(Clone)]
14pub struct RuntimeContext {
15	pub clock: Clock,
16	pub rng: Rng,
17}
18
19impl RuntimeContext {
20	/// Create a runtime context with the given clock and RNG.
21	pub fn new(clock: Clock, rng: Rng) -> Self {
22		Self {
23			clock,
24			rng,
25		}
26	}
27
28	/// Create a runtime context with the given clock and OS RNG.
29	pub fn with_clock(clock: Clock) -> Self {
30		Self {
31			clock,
32			rng: Rng::default(),
33		}
34	}
35
36	/// Create a runtime context with a mock clock and seeded RNG (for testing).
37	pub fn testing(initial_millis: u64, seed: u64) -> Self {
38		Self {
39			clock: Clock::Mock(MockClock::from_millis(initial_millis)),
40			rng: Rng::seeded(seed),
41		}
42	}
43}