[−][src]Struct tokio_etcd_lock::Lease
Implementations
impl Lease
[src]
pub async fn release(self) -> Result<(), Error>
[src]
Stop the keep-alive task, propagating any errors that it may have encountered,
and ask the etcd cluster to revoke this lease. Any etcd keys associated with this lease,
including keys used as locks by this library's LockGuard
, will be removed.
See also: etcd docs
pub async fn lock<'l, 'n>(
&'l mut self,
name: &'n str
) -> Result<LockGuard<'l, 'n>, Error>
[src]
&'l mut self,
name: &'n str
) -> Result<LockGuard<'l, 'n>, Error>
pub async fn try_lock<'l, 'n>(
&'l mut self,
name: &'n str
) -> Result<LockGuard<'l, 'n>, Error>
[src]
&'l mut self,
name: &'n str
) -> Result<LockGuard<'l, 'n>, Error>
Anologous to lock
, but if the lock is taken, return Error::Taken
instead of waiting for the lock
to become available.
pub async fn with_lock<F, Fut, T, '_, '_>(
&'_ mut self,
name: &'_ str,
f: F
) -> Result<T, Error> where
F: FnOnce() -> Fut,
Fut: Future<Output = T>,
[src]
&'_ mut self,
name: &'_ str,
f: F
) -> Result<T, Error> where
F: FnOnce() -> Fut,
Fut: Future<Output = T>,
Run and await future-returning function f
, but only in the context of an acquired lock.
Attempt to acquire lock with name
, waiting for it to become available if needed, and run f
after
it is successfuly acquired. After f
is finished and the future it returned is awaited, the lock is released
automatically.
Panic handling
This function does not attempt to catch panics from f
, and does not guarantee that the lock is released in such
cases. If the program exits abruptly, the lock will be not be available to other clients until this lease's TTL runs out.
Example
lease.with_lock("lock-key", || async { println!("Holding mutually exclusive access to the lock!"); }).await?; // at this point, the lock has been released and is available for other clients
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Lease
impl Send for Lease
impl Sync for Lease
impl Unpin for Lease
impl !UnwindSafe for Lease
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoRequest<T> for T
[src]
fn into_request(self) -> Request<T>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,