Replies: 2 comments 4 replies
-
I also will add that I ran into an additional issue in my case. I need |
Beta Was this translation helpful? Give feedback.
0 replies
-
We don't need a broad |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the last two years, I have encountered this issue at least three times and I have worked for days and never came up with an answer, including after talking with the team here. My current issue is that I need to be able to support a serial port that is transformed into an async stream of data by an API, which I then graph in
iced
. I have a dynamic number of these serial ports, and each may have a different protocol associated with it. They can be spawned dynamically in the UI. Let me explain why it is so difficult with the current API to support this use case without resorting to polling usingtime::every
.The first thing that is suggested is to support this with a
Subscription
. The subscription has a hash associated with it which allows it to continue running so long as the hash does not change. If it does change, then the previous subscription is removed and replaced with the new one. However, an issue arises. If I create aSubscription
in any way, such as withsubscription::Run
, then I may also create the underlyingStream
without knowing whether or not theStream
will be used. I have a stateful serial port which talks to embedded devices, so if I try to create aStream
, I will have to open up a serial stream and several intermediary things that perform the communication back and forth and mediate the creation of messages via a protocol. These things cannot be instantiated multiple times, and it will fail if I attempt to create a second stream. Even if I could create a second stream, it is inherently stateful, with multiple intermediary state machines. Note that this could still be implemented with aRecipe
so long as theRecipe
didn't form theStream
until it was asked for.My suggestion to the team for how to make it simpler for people to use
Subscription
would be to add a new API. Theiced_native::subscription
module should contain a new function that takes three arguments, the first some data, the second a closure that produces the hash ID, and the third a closure that produces theBoxStream
. Ideally, if this API could be added directly toSubscription
, I think it would solve a lot of headaches. You could add a non-streamSubscription
method that just uses a future that returns a tuple with the message and some other arbitrary type that could be the remainder of the stream (viaStream::into_future
). I am not sure why the base subscription module doesn't have therun
API on it, but as mentioned, even therun
API is not sufficient for many use cases, including every use case I have used it for thus far.Another way would be if you could just add subscriptions (as simple async
Stream
) statefully and remove them using an ID when they are no longer needed inside ofupdate()
. Since this isn't in the spirit oficed
I assume this won't be done, but it would make implementation substantially easier for me.The second thing that may be suggested is to handle this in
update()
withCommand
. Unfortunately, it seems thatClone
andDebug
is a requirement for theApplication::Message
. This prevents me from usingCommand::perform
and putting the output of the stream and the rest of the stream withStreamExt::into_future
into the message. If theApplication::Message
could be relaxed to not have thisClone + Debug
requirement, this would resolve this issue.iced
already has full control over my application, so I can create the stream at any point thaticed
would like, but I have been unsuccessful in the last day in finding a way to make this work, and I have only narrowly come to a solution. None of the examples covered this common case. I have referred back to my previous conversations with @hecrj, but none of the solutions work for this particular application. To be clear, it took me quite a long time to figure out how to make this work despite substantial effort. Ultimately, many resort to simply polling a synchronous channel with infinite bound, as I have in my last 6iced
projects, and moving the statefulness out of iced. At the very least, I think there must be a better way to construct this API. Based on what I am seeing in the discussions and what I have seen in the issue tracker, it seems many don't leave with a solution on how to useSubscription
. The built-in subscriptions (likeevery
) do work, but they are simple in nature. Many other applications depend on stateful elements of servers, connections, IPC, files, and other things. Nonetheless, UIs do still need to be created for these things. As it stands, I haven't found a UI framework that works nearly as well and easily asiced
, and so, despite the difficulty, I still find it best to useiced
to create my applications even when it doesn't fit as well. I think changing theSubscription
API to support this use case would be of great value for people like me so that we don't need to implement theRecipe
trait or resort to channels.This would also resolve #1310.
Beta Was this translation helpful? Give feedback.
All reactions