1.0.2 • Published 2 years ago

pg-mutex-lock v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

PG Mutex Lock

Description

This is mutex lock implementation using postgres advisory lock feature.

Feature

  • Support multi-process mutex lock
  • Support single-process mutex lock
  • Support retry, timeout configuration
  • Full typescript support

API

class PGMutexLock

This class is entry point of features. All functions are located under this class instance.

Options

NameTypeRequiredDefaultDescription
database.hoststringnoundefinedpostgres database hostname
database.portnumbernoundefinedpostgres database port
database.databasestringnoundefinedpostgres database database name
database.userstringnoundefinedpostgres database user
database.passwordstringnoundefinedpostgres database password
timeoutnumberno10 * 1000acquire lock timeout
retryCountnumberno3acquire lock retry count

Method acquireLock (key: string) : Promise

Try to acquire lock for given key. If success, will be resolved with true. If failed, will be rejected.

Method releaseLock (key: string) : Promise

Try to release lock for given key. It directly return results of pg_advisory_unlock.

Dependencies

1.0.2

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago