Struct sp_runtime::offchain::storage_lock::StorageLock[][src]

pub struct StorageLock<'a, L = Time> { /* fields omitted */ }

Storage based lock.

A lock that is persisted in the DB and provides the ability to guard against concurrent access in an off-chain worker, with a defined expiry deadline based on the concrete Lockable implementation.

Implementations

impl<'a, L: Lockable + Default> StorageLock<'a, L>[src]

pub fn new(key: &'a [u8]) -> Self[src]

Create a new storage lock with a default() instance of type L.

impl<'a, L: Lockable> StorageLock<'a, L>[src]

pub fn with_lockable(key: &'a [u8], lockable: L) -> Self[src]

Create a new storage lock with an explicit instance of a lockable L.

pub fn try_lock(
    &mut self
) -> Result<StorageLockGuard<'a, '_, L>, <L as Lockable>::Deadline>
[src]

A single attempt to lock using the storage entry.

Returns a lock guard on success, otherwise an error containing the <Self::Lockable>::Deadline in for the currently active lock by another task Err(<L as Lockable>::Deadline).

pub fn lock(&mut self) -> StorageLockGuard<'a, '_, L>[src]

Repeated lock attempts until the lock is successfully acquired.

If one uses fn forget(..), it is highly likely fn try_lock(..) is the correct API to use instead of fn lock(..), since that might never unlock in the anticipated span i.e. when used with BlockAndTime during a certain block number span.

impl<'a> StorageLock<'a, Time>[src]

pub fn with_deadline(key: &'a [u8], expiration_duration: Duration) -> Self[src]

Explicitly create a time based storage lock with a non-default expiration timeout.

impl<'a, B> StorageLock<'a, BlockAndTime<B>> where
    B: BlockNumberProvider
[src]

pub fn with_block_and_time_deadline(
    key: &'a [u8],
    expiration_block_number_offset: u32,
    expiration_duration: Duration
) -> Self
[src]

Explicitly create a time and block number based storage lock with a non-default expiration duration and block number offset.

pub fn with_block_deadline(
    key: &'a [u8],
    expiration_block_number_offset: u32
) -> Self
[src]

Explicitly create a time and block number based storage lock with the default expiration duration and a non-default block number offset.

Auto Trait Implementations

impl<'a, L> RefUnwindSafe for StorageLock<'a, L> where
    L: RefUnwindSafe

impl<'a, L> Send for StorageLock<'a, L> where
    L: Send

impl<'a, L> Sync for StorageLock<'a, L> where
    L: Sync

impl<'a, L> Unpin for StorageLock<'a, L> where
    L: Unpin

impl<'a, L> UnwindSafe for StorageLock<'a, L> where
    L: UnwindSafe

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> CheckedConversion for T[src]

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

impl<T> Instrument for T[src]

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

impl<T, Outer> IsWrappedBy<Outer> for T where
    T: From<Outer>,
    Outer: AsRef<T> + AsMut<T> + From<T>, 
[src]

pub fn from_ref(outer: &Outer) -> &T[src]

Get a reference to the inner from the outer.

pub fn from_mut(outer: &mut Outer) -> &mut T[src]

Get a mutable reference to the inner from the outer.

impl<T> MaybeRefUnwindSafe for T where
    T: RefUnwindSafe
[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

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

type Output = T

Should always be Self

impl<T> SaturatedConversion for T[src]

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<S, T> UncheckedInto<T> for S where
    T: UncheckedFrom<S>, 
[src]

impl<T, S> UniqueSaturatedInto<T> for S where
    T: Bounded,
    S: TryInto<T>, 
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]