pub struct FactorySender<C: FactoryComponent> { /* private fields */ }Expand description
Contains senders to send and receive messages from a Component.
Implementations§
Source§impl<C: FactoryComponent> FactorySender<C>
impl<C: FactoryComponent> FactorySender<C>
Sourcepub fn input_sender(&self) -> &Sender<C::Input>
pub fn input_sender(&self) -> &Sender<C::Input>
Retrieve the sender for input messages.
Useful to forward inputs from another component. If you just need to send input messages,
input() is more concise.
Sourcepub fn output_sender(&self) -> &Sender<C::Output>
pub fn output_sender(&self) -> &Sender<C::Output>
Retrieve the sender for output messages.
Useful to forward outputs from another component. If you just need to send output messages,
output() is more concise.
Examples found in repository?
161 fn init_model(_name: Self::Init, index: &DynamicIndex, sender: FactorySender<Self>) -> Self {
162 let task_index = index.clone();
163
164 let tags = FactoryVecDeque::builder().launch_default().forward(
165 sender.output_sender(),
166 move |output| match output {
167 TagOutput::Delete(tag_index) => {
168 TaskOutput::DeleteTag(task_index.clone(), tag_index)
169 }
170 },
171 );
172
173 Self {
174 name: "".into(),
175 tags,
176 }
177 }Sourcepub fn command_sender(&self) -> &Sender<C::CommandOutput>
pub fn command_sender(&self) -> &Sender<C::CommandOutput>
Retrieve the sender for command output messages.
Useful to forward outputs from another component. If you just need to send output messages,
command() is more concise.
Sourcepub fn input(&self, message: C::Input)
pub fn input(&self, message: C::Input)
Emit an input to the component.
Examples found in repository?
66 fn init_widgets(
67 &mut self,
68 index: &DynamicIndex,
69 root: Self::Root,
70 _returned_widget: >k::Widget,
71 sender: FactorySender<Self>,
72 ) -> Self::Widgets {
73 relm4::view! {
74 #[local_ref]
75 root -> gtk::Box {
76 #[name(label)]
77 gtk::Label {
78 set_label: &self.value.to_string(),
79 set_width_chars: 3,
80 },
81
82 gtk::Button {
83 set_label: "+",
84 connect_clicked => CounterMsg::Increment,
85 },
86
87 gtk::Button {
88 set_label: "-",
89 connect_clicked => CounterMsg::Decrement,
90 },
91
92 gtk::Button {
93 set_label: "Up",
94 connect_clicked[sender, index] => move |_| {
95 sender.output(CounterOutput::MoveUp(index.clone())).unwrap();
96 }
97 },
98
99 gtk::Button {
100 set_label: "Down",
101 connect_clicked[sender, index] => move |_| {
102 sender.output(CounterOutput::MoveDown(index.clone())).unwrap();
103 }
104 },
105
106 gtk::Button {
107 set_label: "To Start",
108 connect_clicked[sender, index] => move |_| {
109 sender.output(CounterOutput::SendFront(index.clone())).unwrap();
110 }
111 }
112 }
113 }
114
115 CounterWidgets { label }
116 }Sourcepub fn output(&self, message: C::Output) -> Result<(), C::Output>
pub fn output(&self, message: C::Output) -> Result<(), C::Output>
Examples found in repository?
66 fn init_widgets(
67 &mut self,
68 index: &DynamicIndex,
69 root: Self::Root,
70 _returned_widget: >k::Widget,
71 sender: FactorySender<Self>,
72 ) -> Self::Widgets {
73 relm4::view! {
74 #[local_ref]
75 root -> gtk::Box {
76 #[name(label)]
77 gtk::Label {
78 set_label: &self.value.to_string(),
79 set_width_chars: 3,
80 },
81
82 gtk::Button {
83 set_label: "+",
84 connect_clicked => CounterMsg::Increment,
85 },
86
87 gtk::Button {
88 set_label: "-",
89 connect_clicked => CounterMsg::Decrement,
90 },
91
92 gtk::Button {
93 set_label: "Up",
94 connect_clicked[sender, index] => move |_| {
95 sender.output(CounterOutput::MoveUp(index.clone())).unwrap();
96 }
97 },
98
99 gtk::Button {
100 set_label: "Down",
101 connect_clicked[sender, index] => move |_| {
102 sender.output(CounterOutput::MoveDown(index.clone())).unwrap();
103 }
104 },
105
106 gtk::Button {
107 set_label: "To Start",
108 connect_clicked[sender, index] => move |_| {
109 sender.output(CounterOutput::SendFront(index.clone())).unwrap();
110 }
111 }
112 }
113 }
114
115 CounterWidgets { label }
116 }Sourcepub fn command<Cmd, Fut>(&self, cmd: Cmd)where
Cmd: FnOnce(Sender<C::CommandOutput>, ShutdownReceiver) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send,
pub fn command<Cmd, Fut>(&self, cmd: Cmd)where
Cmd: FnOnce(Sender<C::CommandOutput>, ShutdownReceiver) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send,
Spawns an asynchronous command.
You can bind the the command to the lifetime of the component
by using a ShutdownReceiver.
Sourcepub fn spawn_command<Cmd>(&self, cmd: Cmd)
pub fn spawn_command<Cmd>(&self, cmd: Cmd)
Spawns a synchronous command.
This is particularly useful for CPU-intensive background jobs that need to run on a thread-pool in the background.
If you expect the component to be dropped while the command is running take care while sending messages!
Sourcepub fn oneshot_command<Fut>(&self, future: Fut)
pub fn oneshot_command<Fut>(&self, future: Fut)
Spawns a future that will be dropped as soon as the factory component is shut down.
Essentially, this is a simpler version of Self::command().
Sourcepub fn spawn_oneshot_command<Cmd>(&self, cmd: Cmd)
pub fn spawn_oneshot_command<Cmd>(&self, cmd: Cmd)
Spawns a synchronous command that will be dropped as soon as the factory component is shut down.
Essentially, this is a simpler version of Self::spawn_command().