Skip to main content

fileloft_core/
lock.rs

1use crate::{error::TusError, info::UploadId};
2
3/// A held lock. Dropping does NOT release it — call `release()` explicitly to
4/// allow async cleanup. Implementations should panic or log on drop if not released.
5#[trait_variant::make(SendLock: Send)]
6pub trait Lock {
7    async fn release(self) -> Result<(), TusError>;
8}
9
10/// Concurrency guard — one exclusive lock per upload ID.
11///
12/// The `Send`-safe variant `SendLocker` is generated by `trait_variant`.
13#[trait_variant::make(SendLocker: Send)]
14pub trait Locker {
15    type LockType: SendLock;
16
17    /// Acquire an exclusive lock for the given upload ID.
18    /// Should block (respecting a timeout) rather than fail immediately.
19    async fn acquire(&self, id: &UploadId) -> Result<Self::LockType, TusError>;
20}