pub struct TransferRegistry {
transfers: HashMap<String, Transfer>,
cancel_tokens: HashMap<String, CancelToken>,
}Expand description
In-memory registry of active and recently-completed transfers.
Thread-safe via Arc<RwLock<TransferRegistry>>. Commands register a
transfer, spawn the work, and the work task calls back via update.
Fields§
§transfers: HashMap<String, Transfer>§cancel_tokens: HashMap<String, CancelToken>Implementations§
Source§impl TransferRegistry
impl TransferRegistry
pub fn new() -> Self
Sourcepub fn register(&mut self, transfer: Transfer) -> (String, Receiver<()>)
pub fn register(&mut self, transfer: Transfer) -> (String, Receiver<()>)
Register a new transfer and return its id (UUID v4).
Returns (id, cancel_receiver) — the caller spawns the task with
the receiver so it can detect a cancel signal.
Sourcepub fn update<F>(&mut self, id: &str, mutator: F) -> Result<(), AppError>
pub fn update<F>(&mut self, id: &str, mutator: F) -> Result<(), AppError>
Apply a mutator closure to the transfer with id.
Returns AppError::NotFound when the id is unknown.
Sourcepub fn cancel(&mut self, id: &str) -> Result<(), AppError>
pub fn cancel(&mut self, id: &str) -> Result<(), AppError>
Send the cancellation signal to the transfer with id.
The cancel token is consumed on first call; subsequent calls on the
same id return Ok(()) (idempotent).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TransferRegistry
impl !RefUnwindSafe for TransferRegistry
impl Send for TransferRegistry
impl Sync for TransferRegistry
impl Unpin for TransferRegistry
impl UnsafeUnpin for TransferRegistry
impl !UnwindSafe for TransferRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
The none-equivalent value.