-
I think of subscription as long running process (stream of values), so I create it, then it is passed to the runtime, and I don't need to create another one, and when the next command happens (subscription method is called) - I return Subscription::none. But right after this previous subscriptions are dropped? EDIT: I'm creating channel let (tx, mut rx) = futures::channel::mpsc::unbounded() and I need to convert every message from rx to application message (update function call) - where should rx be located ? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 6 replies
-
The subscriptions you return are telling iced to check that subscription each cycle. Iced checks the hash value of the subscription. If it changed then it produces a message for you app If the hash is the same, then no message is produced. The subscription function is run every cycle, and what you return is what is checked for changes that cycle. So the async task can keep running, just iced stops checking for changes when you return If you want to keep checking for changes then keep returning the subscription. If you have multiple subscriptions you need to keep alive then look into |
Beta Was this translation helpful? Give feedback.
-
But at the moment I need to return new instance of subscription every time, I can't return hash only for example to notify the runtime hash didn't change. But, I passed some state on the first creation of subscription, it is not an option for me to create this state every time subscription method is called. |
Beta Was this translation helpful? Give feedback.
-
That's an option for me, but how can I return same subscription instance instead of creating new one? |
Beta Was this translation helpful? Give feedback.
-
You need to make sure that the |
Beta Was this translation helpful? Give feedback.
-
This method |
Beta Was this translation helpful? Give feedback.
-
You should not create your state beforehand. You need to pass the inputs to create your state that you can pass in every subscription call. Alternatively, using a Command instead of a Subscription could work, with a Message variant that you can use to "process" your state in update, and passing the state around via Command. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to map a stream of messages from channel to application message:
As you can see stream of data is created from rx. |
Beta Was this translation helpful? Give feedback.
-
Ok, here is the direct question: I'm creating channel let (tx, mut rx) = futures::channel::mpsc::unbounded() and I need to convert every message from rx to application message (update function call) - where should rx be located ? |
Beta Was this translation helpful? Give feedback.
-
The channel should be created in |
Beta Was this translation helpful? Give feedback.
The channel should be created in
Recipe::stream
and moved inside the returnedStream
. If you want bi-directional communication, you can sendtx
to theApplication
as the first message of the subscription.