nodo_std 0.18.5

Standard codelets for NODO
Documentation
// Copyright 2023 David Weikersdorfer

use nodo::prelude::*;

/// Terminates after certain number of steps.
pub struct Terminator {
    tx_control: std::sync::mpsc::SyncSender<RuntimeControl>,
}

#[derive(Config)]
pub struct TerminatorConfig {
    pub step_count: usize,
}

impl Terminator {
    pub fn new(tx_control: std::sync::mpsc::SyncSender<RuntimeControl>) -> Self {
        Self { tx_control }
    }
}

impl Codelet for Terminator {
    type Status = DefaultStatus;
    type Config = TerminatorConfig;
    type Rx = ();
    type Tx = ();
    type Signals = ();

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

    fn step(&mut self, cx: Context<Self>, _: &mut Self::Rx, _: &mut Self::Tx) -> Outcome {
        println!("term: {}", cx.pulse.step_count);
        if cx.pulse.step_count == cx.config.step_count {
            self.tx_control.send(RuntimeControl::RequestStop)?;
        }
        SUCCESS
    }
}