smartlocks

0.0.4 • Public • Published

Smart Locks

Locking and optimistic locking built over Memory, Redis, Cassandra and Etcd.

Storage

import { StorageKind } from 'smartlocks'
await Mutex(StorageKind.Memory, null)
await Mutex(StorageKind.Redis, null)
await Mutex(StorageKind.Cassandra, null)
await Mutex(StorageKind.Etcd, null)

Mutex

lock(lockId, checkMs = null, ttl = 60) // checkMs in milliseconds, ttl in seconds
release(lockId)
import { Mutex, StorageKind } from 'smartlocks'

const lockId = 'my-id'
const mtx = await Mutex(StorageKind.Memory, null)
await mtx.lock(lockId) // Default check every 100 ms
await mtx.release(lockId)

await mtx.lock(lockId, 1000) // Check every 1000 ms if lock is released
await mtx.release(lockId)

await mtx.lock(lockId, 0) // Acquire or return false, do not try to acquire again
await mtx.release(lockId)

await mtx.lock(lockId, 100, 2) // Acquire and check every 100ms, max lease 2 seconds
await mtx.release(lockId)

Package Sidebar

Install

npm i smartlocks

Weekly Downloads

158

Version

0.0.4

License

ISC

Unpacked Size

11.9 kB

Total Files

21

Last publish

Collaborators

  • dev.smartpricing