PostgreSQL advisory locks utils for node.js.
$ npm i pg-advisory-locks
var pg = require('pg');
var locks = require('pg-advisory-locks');
var url = 'postgres://localhost/postgres';
pg.connection(url, function(err, db) {
if (err) throw err;
locks.withLock(db, 'test-lock', function() {
// lock acquired
});
});
lock(db, name)
unlock(db, name)
withLock(db, name, fn)
tryLock(db, name)
xactLock(db, name)
tryXactLock(db, name)
MIT