Hide Subscription internals
.. and introduce `stream::channel` helper
This commit is contained in:
parent
e50aa03edc
commit
8bc49cd886
11 changed files with 268 additions and 246 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue