@@ -77,6 +77,7 @@ pub enum Status {
77
77
pub struct DownloadManager {
78
78
queue : mpsc:: Sender < DownloadRequest > ,
79
79
semaphore : Arc < Semaphore > ,
80
+ cancel : CancellationToken ,
80
81
}
81
82
82
83
impl Drop for DownloadManager {
@@ -94,6 +95,7 @@ impl DownloadManager {
94
95
let manager = Self {
95
96
queue : tx,
96
97
semaphore : semaphore. clone ( ) ,
98
+ cancel : CancellationToken :: new ( ) ,
97
99
} ;
98
100
// Spawn the dispatcher thread to handle download requests
99
101
tokio:: spawn ( async move { dispatcher_thread ( client, rx, semaphore) . await } ) ;
@@ -115,7 +117,7 @@ impl DownloadManager {
115
117
pub fn add_request ( & self , url : Url , destination : PathBuf ) -> DownloadHandle {
116
118
let ( result_tx, result_rx) = oneshot:: channel ( ) ;
117
119
let ( status_tx, status_rx) = watch:: channel ( Status :: Pending ) ;
118
- let cancel = CancellationToken :: new ( ) ;
120
+ let cancel = self . cancel . child_token ( ) ;
119
121
120
122
let req = DownloadRequest {
121
123
url,
@@ -133,6 +135,10 @@ impl DownloadManager {
133
135
cancel,
134
136
}
135
137
}
138
+
139
+ pub fn cancel_all ( & self ) {
140
+ self . cancel . cancel ( ) ;
141
+ }
136
142
}
137
143
138
144
async fn dispatcher_thread (
0 commit comments