I have a synchronous message sender in another module. I need it to be able to convert it into an iced message once it sends it.
I read about subscriptions, but I’m completely unclear how to properly add this ill-fated receiver to the subscription. If I need to convert a send from an external synchronous sender to an iced mpsc, I think I’ve done it.
What I really need is the send_to_iced_gui(iced_message:Msg) function or something similar.
I spent probably 3 days studying subscriptions, their methods and examples - nothing suggests how you can simply send a message to iced.
[code]
fn subscription(&self) → Subscription {
let rx: Receiver = self.rx;
What should be here?
Is it possible to simply get the data, process it and convert it into an event for the iced depending on the data?
1 link - Subscription in rust: there is no argument provided to “fn some_worker()” in example.
2 link - same problem, no arg to subscription passed
It’s clear that in this situation I can create a global variable, put the receiver there, and simply retrieve it from the global variable, since it’s not clear how it can be passed there normally.
Or start adding the functionality I need to the iced code (“send_to_iced_gui(iced_message:Msg)” method).
Each of these options is bad in its own way: the first is a crutch, the second is most likely reinventing the wheel.
Subscription::with - there is no examples in docs. It is unclear how it handles the absence of an argument passed to the function “fn some_worker()” in Subscription::run(some_worker).
use a stream in a Tasks instead. - Could you tell me more? It seemed to me that the only way to interact was through subscriptions.
I need an example that will help me understand how I can create a handler thread with a context, read a Receiver<…> from it, and, upon receiving a message from the Receiver<..>, send an message to the iced app.