1.0.3 • Published 2 years ago
pglock v1.0.3
pglock
基於 PostgreSQL 互斥鎖 依賴於 advisory-lock
Usage
import PGlock from 'pglock'
const pglock = new PGlock('postgres://user:pass@localhost:3475/dbname')
const mutex = pglock.mutex('some-lock-name')
async function runSerialTaskAsync() {
await mutex.lock()
try {
// Do something...
} finally {
mutex.unlock()
}
}
使用 trylock
import PGlock from 'pglock'
const pglock = new PGlock('postgres://user:pass@localhost:3475/dbname')
const mutex = pglock.mutex('some-lock-name')
async function runSerialTaskAsync() {
if (!await mutex.trylock()) {
return
}
try {
// Do something...
} finally {
mutex.unlock()
}
}
});