Sending a message to my Sandbox App from a background job #937
-
I have my UI set up using iced but I also have jobs running in the background. I want to update my UI based on something happening in my background job such as if an error occurs. For example, I spawn my background task using Does any feature exist to send a message to the App on demand from within my code? It should still go through the same message pipeline as the UI messages, or if there is another way perhaps that works too. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Depends on what exactly you want. Using If you are looking to start an async operation from you application and then get a response when it finished (succeeds/fails) then a Otherwise you will need to create a subscription. Which are more difficult to implement. |
Beta Was this translation helpful? Give feedback.
-
Also, you can't use a |
Beta Was this translation helpful? Give feedback.
-
The best way to implement a background task with This task will get continually polled and you'll be able to send messages directly to your App's You can see a comprehensive example of how this done for a task that downloads something, and continually sends updates of the download progress here: https://github.com/hecrj/iced/blob/master/examples/download_progress/src/download.rs |
Beta Was this translation helpful? Give feedback.
The best way to implement a background task with
iced
is to implement your task as an iced_native::subscription::Recipe and add it as a subscription withApplication::subcription
/Subscription::from_recipe
.This task will get continually polled and you'll be able to send messages directly to your App's
Message
/update
.You can see a comprehensive example of how this done for a task that downloads something, and continually sends updates of the download progress here:
https://github.com/hecrj/iced/blob/master/examples/download_progress/src/download.rs