Struct tokio_etcd_lock::Lease[][src]

pub struct Lease { /* fields omitted */ }

Implementations

impl Lease[src]

pub async fn release(self, client: &mut Client) -> 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,
    client: &mut Client,
    name: &'n str
) -> Result<LockGuard<'l, 'n>, Error>
[src]

pub async fn try_lock<'l, 'n>(
    &'l mut self,
    client: &mut Client,
    name: &'n str
) -> Result<LockGuard<'l, 'n>, Error>
[src]

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,
    client: &mut Client,
    name: &str,
    f: F
) -> Result<T, Error> where
    F: FnOnce() -> Fut,
    Fut: Future<Output = T>, 
[src]

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

impl Clone for Lease[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoRequest<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]