pub struct Downloads<T> {
pub(crate) waker: Arc<dyn Waker>,
pub(crate) sender: Sender<(DownloadId, Report)>,
pub(crate) receiver: Receiver<(DownloadId, Report)>,
pub(crate) running: RefCell<HashMap<DownloadId, Running<T>>>,
}Expand description
The downloads an app has running, and the channel their reports arrive on.
Fields§
§waker: Arc<dyn Waker>§sender: Sender<(DownloadId, Report)>§receiver: Receiver<(DownloadId, Report)>§running: RefCell<HashMap<DownloadId, Running<T>>>Implementations§
Source§impl<T> Downloads<T>
impl<T> Downloads<T>
Sourcepub fn new(waker: Arc<dyn Waker>) -> Self
pub fn new(waker: Arc<dyn Waker>) -> Self
waker asks the UI thread to call Downloads::receive.
pub fn start(&self, request: Request<T>)
Sourcepub fn command(&self, id: &str, command: DownloadCommand)
pub fn command(&self, id: &str, command: DownloadCommand)
Asks the download whose id id shows to do command. An id of no running download,
such as one that has just finished, asks nothing.
Sourcepub fn receive<E>(
&self,
follow: impl FnMut(&mut T) -> bool,
apply: impl FnMut(&T, &Report) -> Result<(), E>,
) -> Result<(), E>
pub fn receive<E>( &self, follow: impl FnMut(&mut T) -> bool, apply: impl FnMut(&T, &Report) -> Result<(), E>, ) -> Result<(), E>
Hands each report that has arrived to apply with where it goes, forgetting
downloads that have finished. follow first moves a download’s targets to where its
item is now, or says the app no longer holds it, which cancels it. Stops at the
first error, leaving later reports queued.
§Errors
The first error apply returns.
§Panics
When a report arrives from a download this doesn’t know, which can’t happen: each is forgotten only after its last report.
Sourcepub fn cancel_unheld(&self, follow: impl FnMut(&mut T) -> bool)
pub fn cancel_unheld(&self, follow: impl FnMut(&mut T) -> bool)
Cancels each download whose item follow no longer finds, after the app’s code
changed state, and keeps the rest’s targets where their items are.