2/n Add pause/start actions
This commit is contained in:
parent
0c4844f534
commit
b79a21179f
3 changed files with 19 additions and 16 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue