pub struct MemoryTaskLock { /* private fields */ }Expand description
In-memory task lock for single-process testing
§Examples
use reinhardt_tasks::{MemoryTaskLock, TaskLock, TaskId};
use std::time::Duration;
let lock = MemoryTaskLock::new();
let task_id = TaskId::new();
// Acquire lock
let token = lock.acquire(task_id, Duration::from_secs(60)).await?;
assert!(token.is_some());
// Check if locked
let is_locked = lock.is_locked(task_id).await?;
assert!(is_locked);
// Release lock
let released = lock.release(task_id, &token.unwrap()).await?;
assert!(released);Implementations§
Trait Implementations§
Source§impl Default for MemoryTaskLock
impl Default for MemoryTaskLock
Source§impl TaskLock for MemoryTaskLock
impl TaskLock for MemoryTaskLock
Source§fn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: TaskId,
token: &'life1 LockToken,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = TaskResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: TaskId,
token: &'life1 LockToken,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = TaskResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Atomically extend the TTL of an existing lock.
Unlike the default trait implementation which releases then re-acquires, this holds the write lock throughout the operation to prevent another worker from stealing the lock in between.
Source§fn acquire<'life0, 'async_trait>(
&'life0 self,
task_id: TaskId,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = TaskResult<Option<LockToken>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn acquire<'life0, 'async_trait>(
&'life0 self,
task_id: TaskId,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = TaskResult<Option<LockToken>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Acquire a lock for a task Read more
Auto Trait Implementations§
impl Freeze for MemoryTaskLock
impl !RefUnwindSafe for MemoryTaskLock
impl Send for MemoryTaskLock
impl Sync for MemoryTaskLock
impl Unpin for MemoryTaskLock
impl UnsafeUnpin for MemoryTaskLock
impl !UnwindSafe for MemoryTaskLock
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