|
1 | 1 | use std::collections::BTreeMap;
|
2 | 2 | use std::sync::Arc;
|
3 | 3 |
|
4 |
| -use futures::executor::block_on; |
5 | 4 | use futures::future::join_all;
|
6 | 5 |
|
7 | 6 | use super::{Repository, UpdateTorrentSync};
|
@@ -59,6 +58,7 @@ impl Repository<entry::MutexStd> for TorrentsRwLockStdMutexStd {
|
59 | 58 | async fn get_metrics(&self) -> TorrentsMetrics {
|
60 | 59 | let metrics: Arc<tokio::sync::Mutex<TorrentsMetrics>> = Arc::default();
|
61 | 60 |
|
| 61 | + // todo:: replace with a ring buffer |
62 | 62 | let mut handles = Vec::<tokio::task::JoinHandle<()>>::default();
|
63 | 63 |
|
64 | 64 | for e in self.get_torrents().values() {
|
@@ -114,19 +114,20 @@ impl Repository<entry::MutexStd> for TorrentsRwLockStdMutexStd {
|
114 | 114 | }
|
115 | 115 |
|
116 | 116 | async fn remove_inactive_peers(&self, max_peer_timeout: u32) {
|
117 |
| - let db = self.get_torrents(); |
| 117 | + // todo:: replace with a ring buffer |
| 118 | + let mut handles = Vec::<tokio::task::JoinHandle<()>>::default(); |
118 | 119 |
|
119 |
| - let futures = db.values().map(|e| { |
| 120 | + for e in self.get_torrents().values() { |
120 | 121 | let entry = e.clone();
|
121 |
| - tokio::spawn(async move { |
| 122 | + handles.push(tokio::task::spawn(async move { |
122 | 123 | entry
|
123 | 124 | .lock()
|
124 | 125 | .expect("it should get lock for entry")
|
125 | 126 | .remove_inactive_peers(max_peer_timeout);
|
126 |
| - }) |
127 |
| - }); |
| 127 | + })); |
| 128 | + } |
128 | 129 |
|
129 |
| - block_on(join_all(futures)); |
| 130 | + join_all(handles).await; |
130 | 131 | }
|
131 | 132 |
|
132 | 133 | async fn remove_peerless_torrents(&self, policy: &crate::core::TrackerPolicy) {
|
|
0 commit comments