Skip to content

forkzero/cloudlock-js

Repository files navigation

Actions Status codecov Dependency Status Known Vulnerabilities

cloudlock-js

*** coming soon, if you need this please email gmoon@forkzero.com ***

JavaScript client for the FORKZERO Cloud Lock service

Use Cases

  • Lock/unlock for exclusive access to a resource for distributed, uncoordinated clients

Install

npm install cloudlock --save

Use

// CommonJS
const CloudLock = require('cloudlock')

// es6
import CloudLock from 'cloudlock'

const resource = new CloudLock('my-resource')`

Lock for Distributed Computing

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

Check to see if a resource is locked

const resource = new CloudLock('my-resource');

if (!resource.status().locked) {
  // resource is not locked; proceed
}

About

JavaScript client for the FORKZERO Cloud Lock service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages