From 6ccc828607b22a0583c12bad638ee2bc7e7310b8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Nov 2024 02:14:33 +0100 Subject: Use `Task::run` in `download_progress` example --- examples/download_progress/src/download.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'examples/download_progress/src/download.rs') diff --git a/examples/download_progress/src/download.rs b/examples/download_progress/src/download.rs index a8e7b404..d63fb906 100644 --- a/examples/download_progress/src/download.rs +++ b/examples/download_progress/src/download.rs @@ -1,24 +1,13 @@ use iced::futures::{SinkExt, Stream, StreamExt}; use iced::stream::try_channel; -use iced::Subscription; -use std::hash::Hash; use std::sync::Arc; -// Just a little utility function -pub fn file( - id: I, - url: T, -) -> iced::Subscription<(I, Result)> { - Subscription::run_with_id( - id, - download(url.to_string()).map(move |progress| (id, progress)), - ) -} - -fn download(url: String) -> impl Stream> { +pub fn download( + url: impl AsRef, +) -> impl Stream> { try_channel(1, move |mut output| async move { - let response = reqwest::get(&url).await?; + let response = reqwest::get(url.as_ref()).await?; let total = response.content_length().ok_or(Error::NoContentLength)?; let _ = output.send(Progress::Downloading { percent: 0.0 }).await; -- cgit