@@ -190,7 +190,9 @@ where
190
190
191
191
/// Try to lock once, returns whether the lock was obtained or not.
192
192
#[ instrument( skip( self ) , fields( ?self . lock_key, ?self . lock_holder) ) ]
193
- pub async fn try_lock_once ( & self ) -> Result < Option < CrossProcessLockGuard > , LockStoreError > {
193
+ pub async fn try_lock_once (
194
+ & self ,
195
+ ) -> Result < Option < CrossProcessLockGuard > , CrossProcessLockError > {
194
196
// Hold onto the locking attempt mutex for the entire lifetime of this
195
197
// function, to avoid multiple reentrant calls.
196
198
let mut _attempt = self . locking_attempt . lock ( ) . await ;
@@ -212,7 +214,7 @@ where
212
214
. locker
213
215
. try_lock ( LEASE_DURATION_MS , & self . lock_key , & self . lock_holder )
214
216
. await
215
- . map_err ( |err| LockStoreError :: BackingStoreError ( Box :: new ( err) ) ) ?;
217
+ . map_err ( |err| CrossProcessLockError :: TryLockError ( Box :: new ( err) ) ) ?;
216
218
217
219
if !acquired {
218
220
trace ! ( "Couldn't acquire the lock immediately." ) ;
@@ -302,7 +304,7 @@ where
302
304
pub async fn spin_lock (
303
305
& self ,
304
306
max_backoff : Option < u32 > ,
305
- ) -> Result < CrossProcessLockGuard , LockStoreError > {
307
+ ) -> Result < CrossProcessLockGuard , CrossProcessLockError > {
306
308
let max_backoff = max_backoff. unwrap_or ( MAX_BACKOFF_MS ) ;
307
309
308
310
// Note: reads/writes to the backoff are racy across threads in theory, but the
@@ -330,7 +332,7 @@ where
330
332
}
331
333
WaitingTime :: Stop => {
332
334
// We've reached the maximum backoff, abandon.
333
- return Err ( LockStoreError :: LockTimeout ) ;
335
+ return Err ( CrossProcessLockError :: LockTimeout ) ;
334
336
}
335
337
} ;
336
338
@@ -348,18 +350,18 @@ where
348
350
349
351
/// Error related to the locking API of the store.
350
352
#[ derive( Debug , thiserror:: Error ) ]
351
- pub enum LockStoreError {
353
+ pub enum CrossProcessLockError {
352
354
/// Spent too long waiting for a database lock.
353
355
#[ error( "a lock timed out" ) ]
354
356
LockTimeout ,
355
357
356
358
#[ error( transparent) ]
357
359
#[ cfg( not( target_family = "wasm" ) ) ]
358
- BackingStoreError ( #[ from] Box < dyn Error + Send + Sync > ) ,
360
+ TryLockError ( #[ from] Box < dyn Error + Send + Sync > ) ,
359
361
360
362
#[ error( transparent) ]
361
363
#[ cfg( target_family = "wasm" ) ]
362
- BackingStoreError ( Box < dyn Error > ) ,
364
+ TryLockError ( Box < dyn Error > ) ,
363
365
}
364
366
365
367
#[ cfg( test) ]
@@ -379,8 +381,8 @@ mod tests {
379
381
} ;
380
382
381
383
use super :: {
382
- CrossProcessLock , CrossProcessLockGuard , EXTEND_LEASE_EVERY_MS , LockStoreError , TryLock ,
383
- memory_store_helper:: try_take_leased_lock,
384
+ CrossProcessLock , CrossProcessLockError , CrossProcessLockGuard , EXTEND_LEASE_EVERY_MS ,
385
+ TryLock , memory_store_helper:: try_take_leased_lock,
384
386
} ;
385
387
386
388
#[ derive( Clone , Default ) ]
@@ -416,7 +418,7 @@ mod tests {
416
418
sleep ( Duration :: from_millis ( EXTEND_LEASE_EVERY_MS ) ) . await ;
417
419
}
418
420
419
- type TestResult = Result < ( ) , LockStoreError > ;
421
+ type TestResult = Result < ( ) , CrossProcessLockError > ;
420
422
421
423
#[ async_test]
422
424
async fn test_simple_lock_unlock ( ) -> TestResult {
@@ -518,7 +520,7 @@ mod tests {
518
520
. expect ( "lock was obtained after spin-locking" ) ;
519
521
520
522
// Now if lock1 tries to get the lock with a small timeout, it will fail.
521
- assert_matches ! ( lock1. spin_lock( Some ( 200 ) ) . await , Err ( LockStoreError :: LockTimeout ) ) ;
523
+ assert_matches ! ( lock1. spin_lock( Some ( 200 ) ) . await , Err ( CrossProcessLockError :: LockTimeout ) ) ;
522
524
523
525
Ok ( ( ) )
524
526
}
0 commit comments