Struct tokio_etcd_lock::Lease

source ·
pub struct Lease { /* private fields */ }

Implementations§

source§

impl Lease

source

pub async fn release(self, client: &mut Client) -> Result<(), Error>

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

source

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

source

pub async fn try_lock<'l, 'n>( &'l mut self, client: &mut Client, 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.

source

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>,

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(&mut client, "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§

source§

impl Clone for Lease

source§

fn clone(&self) -> Lease

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more