@@ -38,13 +38,13 @@ $locker = new \Cog\DbLocker\Locker\PostgresAdvisoryLocker();
38
38
$lockId = \Cog\DbLocker\LockId\PostgresLockId::fromKeyValue('user', '4');
39
39
40
40
$dbConnection->beginTransaction();
41
- $isLockAcquired = $locker->acquireTransactionLevelLock (
41
+ $lock = $locker->acquireSessionLevelLockHandler (
42
42
$dbConnection,
43
43
$lockId,
44
44
\Cog\DbLocker\Locker\PostgresAdvisoryLockWaitModeEnum::NonBlocking,
45
45
\Cog\DbLocker\Locker\PostgresLockAccessModeEnum::Exclusive,
46
46
);
47
- if ($isLockAcquired ) {
47
+ if ($lock->wasAcquired ) {
48
48
// Execute logic if lock was successful
49
49
} else {
50
50
// Execute logic if lock acquisition has been failed
@@ -60,18 +60,21 @@ $dbConnection = new PDO($dsn, $username, $password);
60
60
$locker = new \Cog\DbLocker\Locker\PostgresAdvisoryLocker();
61
61
$lockId = \Cog\DbLocker\LockId\PostgresLockId::fromKeyValue('user', '4');
62
62
63
- $isLockAcquired = $locker->acquireSessionLevelLock(
64
- $dbConnection,
65
- $lockId,
66
- \Cog\DbLocker\Locker\PostgresAdvisoryLockWaitModeEnum::NonBlocking,
67
- \Cog\DbLocker\Locker\PostgresLockAccessModeEnum::Exclusive,
68
- );
69
- if ($isLockAcquired) {
70
- // Execute logic if lock was successful
71
- } else {
72
- // Execute logic if lock acquisition has been failed
63
+ try {
64
+ $lock = $locker->acquireSessionLevelLockHandler(
65
+ $dbConnection,
66
+ $lockId,
67
+ \Cog\DbLocker\Locker\PostgresAdvisoryLockWaitModeEnum::NonBlocking,
68
+ \Cog\DbLocker\Locker\PostgresLockAccessModeEnum::Exclusive,
69
+ );
70
+ if ($lock->wasAcquired) {
71
+ // Execute logic if lock was successful
72
+ } else {
73
+ // Execute logic if lock acquisition has been failed
74
+ }
75
+ } finally {
76
+ $lock->release();
73
77
}
74
- $locker->releaseSessionLevelLock($dbConnection, $lockId);
75
78
```
76
79
77
80
## Changelog
0 commit comments