nodo_std 0.18.5

Standard codelets for NODO
Documentation
// Copyright 2023 David Weikersdorfer

use nodo::prelude::*;

/// Publishes messages generated by a lambda
pub struct Generator<F>(F);

impl<F> Generator<F> {
    pub fn new(impf: F) -> Self {
        Self(impf)
    }
}

impl<F, V> Codelet for Generator<F>
where
    F: FnMut() -> V + Send,
    V: Clone + Send + Sync,
{
    type Status = DefaultStatus;
    type Config = ();
    type Rx = ();
    type Tx = MessageTx<V>;
    type Signals = ();

    fn build_bundles(_: &Self::Config) -> (Self::Rx, Self::Tx) {
        ((), MessageTx::new(1))
    }

    fn step(&mut self, cx: Context<Self>, _: &mut Self::Rx, tx: &mut Self::Tx) -> Outcome {
        tx.push(cx.clocks.sys_mono.now(), (self.0)())?;
        SUCCESS
    }
}