logic_mesh/tokio_impl/
output.rs

1// Copyright (c) 2022-2023, Radu Racariu.
2
3use libhaystack::val::Value;
4
5use crate::base::{
6    input::InputProps,
7    link::{BaseLink, LinkState},
8    output::{BaseOutput, Output},
9};
10
11use super::input::{InputImpl, Writer};
12
13pub type LinkImpl = BaseLink<Writer>;
14pub type OutputImpl = BaseOutput<LinkImpl>;
15
16impl Output for OutputImpl {
17    type Writer = <InputImpl as InputProps>::Writer;
18
19    fn add_link(&mut self, link: BaseLink<Self::Writer>) {
20        self.links.push(link);
21    }
22
23    fn set(&mut self, value: Value) {
24        for link in &mut self.links {
25            if let Some(tx) = &link.tx {
26                if let Err(__) = tx.try_send(value.clone()) {
27                    link.state = LinkState::Error;
28                } else {
29                    link.state = LinkState::Connected;
30                }
31            }
32        }
33        self.value = value;
34    }
35}