Skip to content

Commit 8cf8014

Browse files
committed
Leave only *Handler API
1 parent 0205b4b commit 8cf8014

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ $dbConnection->commit();
5454

5555
#### Session-level advisory lock
5656

57+
Callback API
58+
59+
```php
60+
$dbConnection = new PDO($dsn, $username, $password);
61+
62+
$locker = new \Cog\DbLocker\Postgres\PostgresAdvisoryLocker();
63+
$lockId = \Cog\DbLocker\Postgres\PostgresLockKey::create('user', '4');
64+
65+
$lock = $locker->withinSessionLevelLock(
66+
$dbConnection,
67+
$lockId,
68+
function (\Cog\DbLocker\Postgres\LockHandle\SessionLevelLockHandle $lock): Payment {
69+
if ($lock->wasAcquired) {
70+
// Execute logic if lock was successful
71+
} else {
72+
// Execute logic if lock acquisition has been failed
73+
}
74+
}
75+
\Cog\DbLocker\Postgres\Enum\PostgresLockWaitModeEnum::NonBlocking,
76+
\Cog\DbLocker\Postgres\Enum\PostgresLockAccessModeEnum::Exclusive,
77+
);
78+
```
79+
80+
Low-level API
5781
```php
5882
$dbConnection = new PDO($dsn, $username, $password);
5983

0 commit comments

Comments
 (0)