[−][src]Struct sp_runtime::offchain::storage_lock::StorageLock
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][−]
&mut self
) -> Result<StorageLockGuard<'a, '_, L>, <L as Lockable>::Deadline>
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][−]
B: BlockNumberProvider,
pub fn with_block_and_time_deadline(
key: &'a [u8],
expiration_block_number_offset: u32,
expiration_duration: Duration
) -> Self[src][−]
key: &'a [u8],
expiration_block_number_offset: u32,
expiration_duration: Duration
) -> Self
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][−]
key: &'a [u8],
expiration_block_number_offset: u32
) -> Self
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,
L: RefUnwindSafe,
impl<'a, L> Send for StorageLock<'a, L> where
L: Send,
L: Send,
impl<'a, L> Sync for StorageLock<'a, L> where
L: Sync,
L: Sync,
impl<'a, L> Unpin for StorageLock<'a, L> where
L: Unpin,
L: Unpin,
impl<'a, L> UnwindSafe for StorageLock<'a, L> where
L: UnwindSafe,
L: UnwindSafe,
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,
impl<T> CheckedConversion for T[src][+]
impl<T> From<T> for T[src][+]
impl<T, U> Into<U> for T where
U: From<T>, [src][+]
U: From<T>,
impl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>, [src][+]
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T> MaybeRefUnwindSafe for T where
T: RefUnwindSafe, [src]
T: RefUnwindSafe,
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][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src][+]
U: TryFrom<T>,
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>, [src][+]
T: UncheckedFrom<S>,
impl<T, S> UniqueSaturatedInto<T> for S where
S: TryInto<T>,
T: Bounded, [src][+]
S: TryInto<T>,
T: Bounded,
impl<V, T> VZip<V> for T where
V: MultiLane<T>, [src][+]
V: MultiLane<T>,