summaryrefslogtreecommitdiffstats
path: root/examples/download_progress
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-05 02:15:13 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-05 02:16:45 +0200
commit8bc49cd88653309f5abe8a38d5a4af36fcfea933 (patch)
tree6c205ff9964cec1d48934b7ff166532491a349c5 /examples/download_progress
parente50aa03edc858d561992d8ca441aa063f273eeac (diff)
downloadiced-8bc49cd88653309f5abe8a38d5a4af36fcfea933.tar.gz
iced-8bc49cd88653309f5abe8a38d5a4af36fcfea933.tar.bz2
iced-8bc49cd88653309f5abe8a38d5a4af36fcfea933.zip
Hide `Subscription` internals
.. and introduce `stream::channel` helper
Diffstat (limited to 'examples/download_progress')
-rw-r--r--examples/download_progress/src/download.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/download_progress/src/download.rs b/examples/download_progress/src/download.rs
index d6cc1e24..bdf57290 100644
--- a/examples/download_progress/src/download.rs
+++ b/examples/download_progress/src/download.rs
@@ -1,4 +1,5 @@
-use iced::subscription;
+use iced::futures;
+use iced::Subscription;
use std::hash::Hash;
@@ -7,9 +8,14 @@ pub fn file<I: 'static + Hash + Copy + Send + Sync, T: ToString>(
id: I,
url: T,
) -> iced::Subscription<(I, Progress)> {
- subscription::unfold(id, State::Ready(url.to_string()), move |state| {
- download(id, state)
- })
+ Subscription::run_with_id(
+ id,
+ futures::stream::unfold(State::Ready(url.to_string()), move |state| {
+ use iced::futures::FutureExt;
+
+ download(id, state).map(Some)
+ }),
+ )
}
async fn download<I: Copy>(id: I, state: State) -> ((I, Progress), State) {