use nodo::prelude::*;
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
}
}