Skip to content

Commit 633b752

Browse files
downloader: Add shutdown, active_downloads and queued_downloads
1 parent ce05710 commit 633b752

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/downloader/manager.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ impl DownloadManager {
8888
pub fn cancel_all(&self) {
8989
self.cancel.cancel();
9090
}
91+
92+
pub fn queued_downloads(&self) -> usize {
93+
self.queue.max_capacity() - self.queue.capacity()
94+
}
95+
96+
pub fn active_downloads(&self) -> usize {
97+
// -1 because the dispatcher thread is always running
98+
self.tracker.len() - 1
99+
}
100+
101+
pub async fn shutdown(self) -> Result<(), Error> {
102+
self.cancel.cancel();
103+
self.tracker.close();
104+
self.tracker.wait().await;
105+
drop(self.queue);
106+
Ok(())
107+
}
91108
}
92109

93110
async fn dispatcher_thread(

0 commit comments

Comments
 (0)