diff --git a/nexosim-util/examples/simulation_driven.rs b/nexosim-util/examples/simulation_driven.rs index 0b4f4e4..6a67378 100644 --- a/nexosim-util/examples/simulation_driven.rs +++ b/nexosim-util/examples/simulation_driven.rs @@ -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) { 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; diff --git a/nexosim-util/src/helper_models.rs b/nexosim-util/src/helper_models.rs index c9a8d80..bc58367 100644 --- a/nexosim-util/src/helper_models.rs +++ b/nexosim-util/src/helper_models.rs @@ -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 { diff --git a/nexosim/src/ports/sink/blocking_event_queue.rs b/nexosim/src/ports/sink/blocking_event_queue.rs index a712ab9..91a719e 100644 --- a/nexosim/src/ports/sink/blocking_event_queue.rs +++ b/nexosim/src/ports/sink/blocking_event_queue.rs @@ -8,9 +8,11 @@ use super::{EventSink, EventSinkStream, EventSinkWriter}; /// A blocking event queue with an unbounded size. /// -/// Implements [`EventSink`], while [`EventSinkStream`] is implemented by -/// [`BlockingEventQueueReader`] available through the -/// [`BlockingEventQueue::reader`] method. +/// Implements [`EventSink`]. +/// +/// Note that [`EventSinkStream`] is implemented by +/// [`BlockingEventQueueReader`], created with the +/// [`BlockingEventQueue::into_reader`] method. pub struct BlockingEventQueue { is_open: Arc, sender: Sender, @@ -20,24 +22,24 @@ pub struct BlockingEventQueue { impl BlockingEventQueue { /// Creates an open `BlockingEventQueue`. pub fn new() -> Self { - Self::new_with_open_state(true) + Self::new_with_state(true) } /// Creates a closed `BlockingEventQueue`. pub fn new_closed() -> Self { - Self::new_with_open_state(false) + Self::new_with_state(false) } - /// Returns consumer handle. - pub fn reader(self) -> BlockingEventQueueReader { + /// Returns a consumer handle. + pub fn into_reader(self) -> BlockingEventQueueReader { BlockingEventQueueReader { is_open: self.is_open, receiver: self.receiver, } } - /// Creates new `BlockingEventQueue` in a given state. - fn new_with_open_state(is_open: bool) -> Self { + /// Creates a new `BlockingEventQueue` in the specified state. + fn new_with_state(is_open: bool) -> Self { let (sender, receiver) = channel(); Self { is_open: Arc::new(AtomicBool::new(is_open)), @@ -70,10 +72,10 @@ impl fmt::Debug for BlockingEventQueue { } } -/// A consumer handle to blocking event queue. +/// A consumer handle of a `BlockingEventQueue`. /// -/// Implements [`EventSinkStream`]. Call to iterator's `next` function is -/// blocking. `None` is returned when simulation is closed. +/// Implements [`EventSinkStream`]. Calls to the iterator's `next` method are +/// blocking. `None` is returned when all writer handles have been dropped. pub struct BlockingEventQueueReader { is_open: Arc, receiver: Receiver,