2/n Add pause/start actions

This commit is contained in:
Igor Katson 2023-11-24 14:29:05 +00:00
parent 0c4844f534
commit b79a21179f
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
3 changed files with 19 additions and 16 deletions

View file

@ -23,6 +23,7 @@ use tokio_stream::StreamExt;
use tracing::trace_span;
use url::Url;
use crate::chunk_tracker::ChunkTracker;
use crate::spawn_utils::spawn;
use crate::spawn_utils::BlockingSpawner;
@ -98,6 +99,15 @@ impl ManagedTorrent {
f(&self.locked.read().state)
}
pub fn with_chunk_tracker<R>(&self, f: impl FnOnce(&ChunkTracker) -> R) -> anyhow::Result<R> {
let g = self.locked.read();
match &g.state {
ManagedTorrentState::Paused(p) => Ok(f(&p.chunk_tracker)),
ManagedTorrentState::Live(l) => Ok(f(&l.lock_read("chunk_tracker").chunks)),
_ => bail!("no chunk tracker, torrent neither paused nor live"),
}
}
pub fn live(&self) -> Option<Arc<TorrentStateLive>> {
let g = self.locked.read();
match &g.state {