Actions Status codecov Dependency Status Known Vulnerabilities
*** coming soon, if you need this please email gmoon@forkzero.com ***
JavaScript client for the FORKZERO Cloud Lock service
- Lock/unlock for exclusive access to a resource for distributed, uncoordinated clients
npm install cloudlock --save
// CommonJS const CloudLock = require('cloudlock') // es6 import CloudLock from 'cloudlock' const resource = new CloudLock('my-resource')`
Obtain a lock
const resource = new CloudLock('myresource'); resource.lock((lock => { if (resource.locked) { // do stuff resource.unlock(); } });
Obtain a lock with progressive retries, up to timeout
const resource = new CloudLock('s3:my-bucket/my-file'); resource.wait() .then(lock=>{ if (resource.locked) { // do stuff resource.unlock(); } }) .catch(error => { // unable to obtain lock before timeout })
Event-based Interface
const resource = new CloudLock('my-business-process'); resource.wait(); resource.on('lock', lock => { if (resource.locked) { // do stuff } resource.unlock(); }) resource.on('timeout', () => { // want to try again? resource.wait(); })
const resource = new CloudLock('my-resource'); if (!resource.status().locked) { // resource is not locked; proceed }