pub struct PgAdvisoryLock { /* private fields */ }Expand description
A PostgreSQL advisory lock identifier.
Advisory locks are application-level locks that don’t lock any table or row. They are useful for coordinating access to external resources.
§Example
use sentinel_driver::advisory_lock::PgAdvisoryLock;
let lock = PgAdvisoryLock::new(12345);
let guard = lock.acquire(conn).await?;
// ... do work under lock ...
guard.release(conn).await?;Implementations§
Source§impl PgAdvisoryLock
impl PgAdvisoryLock
Sourcepub fn from_name(name: &str) -> Self
pub fn from_name(name: &str) -> Self
Create an advisory lock from a string key.
The string is hashed to produce a stable i64 key using the default hasher.
Sourcepub async fn acquire(
&self,
conn: &mut Connection,
) -> Result<PgAdvisoryLockGuard>
pub async fn acquire( &self, conn: &mut Connection, ) -> Result<PgAdvisoryLockGuard>
Acquire this advisory lock (session-scoped, blocks until acquired).
Sourcepub async fn try_acquire(
&self,
conn: &mut Connection,
) -> Result<Option<PgAdvisoryLockGuard>>
pub async fn try_acquire( &self, conn: &mut Connection, ) -> Result<Option<PgAdvisoryLockGuard>>
Try to acquire this advisory lock without blocking.
Returns None if the lock is already held by another session.
Trait Implementations§
Source§impl Clone for PgAdvisoryLock
impl Clone for PgAdvisoryLock
Source§fn clone(&self) -> PgAdvisoryLock
fn clone(&self) -> PgAdvisoryLock
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PgAdvisoryLock
impl Debug for PgAdvisoryLock
impl Copy for PgAdvisoryLock
Auto Trait Implementations§
impl Freeze for PgAdvisoryLock
impl RefUnwindSafe for PgAdvisoryLock
impl Send for PgAdvisoryLock
impl Sync for PgAdvisoryLock
impl Unpin for PgAdvisoryLock
impl UnsafeUnpin for PgAdvisoryLock
impl UnwindSafe for PgAdvisoryLock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more