1
0
forked from ROMEO/nexosim

Changes after review.

This commit is contained in:
Jaŭhien Piatlicki
2025-01-28 11:08:17 +01:00
parent 8a1a6cf354
commit 7ff6f4c6c3
3 changed files with 24 additions and 21 deletions

View File

@ -71,7 +71,7 @@ pub struct Counter {
}
impl Counter {
/// Creates new `Counter` model.
/// Creates a new `Counter` model.
fn new() -> Self {
let mode = Output::default();
let count = Output::default();
@ -122,7 +122,7 @@ pub struct Detector {
}
impl Detector {
/// Creates new `Detector` model.
/// Creates a new `Detector` model.
pub fn new() -> Self {
Self {
pulse: Output::default(),
@ -140,7 +140,7 @@ impl Detector {
self.next = None;
}
/// Generates pulse.
/// Generates a pulse.
///
/// Note: self-scheduling async methods must be for now defined with an
/// explicit signature instead of `async fn` due to a rustc issue.
@ -155,7 +155,7 @@ impl Detector {
}
}
/// Schedules next detection.
/// Schedules the next detection.
async fn schedule_next(&mut self, cx: &mut Context<Self>) {
let next = {
let mut rng = rand::thread_rng();
@ -204,7 +204,7 @@ fn main() -> Result<(), SimulationError> {
counter
.count
.map_connect_sink(|c| Event::Count(*c), &observer);
let mut observer = observer.reader();
let mut observer = observer.into_reader();
// Start time (arbitrary since models do not depend on absolute time).
let t0 = MonotonicTime::EPOCH;

View File

@ -9,20 +9,21 @@ use nexosim::model::{Context, InitializedModel, Model};
/// A ticker model.
///
/// This model self-schedules with a provided period keeping simulation alive.
/// This model self-schedules at the specified period, which can be used to keep
/// the simulation alive.
pub struct Ticker {
/// Tick period in milliseconds.
/// Tick period.
tick: Duration,
}
impl Ticker {
/// Creates new `Ticker` with provided tick period in milliseconds.
/// Creates a new `Ticker` with the specified self-scheduling period.
pub fn new(tick: Duration) -> Self {
Self { tick }
}
/// Self-scheduled function.
pub async fn tick(&mut self) {}
async fn tick(&mut self) {}
}
impl Model for Ticker {