1.0.3 • Published 2 years ago

pglock v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

pglock

基於 PostgreSQL 互斥鎖 依賴於 advisory-lock

npm package

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()
  }
}
});
1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago