grpc-mutex-client
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

Actions Status Actions Status Actions Status Test Coverage Maintainability npm version

Client library for nodejs-grpc-mutex-api

How to Install

npm i grpc-mutex-client

How to use

First, you need to have a single instance (with no horizontal scaling) of grpc-mutex-api running. Then, obtain an instance of Mutex:

const client = new MutexApiClient('example.com');

Then, just acquire and release an id as you need:

const release = await client.acquire({ id: 'my-mutex-id' });

// Here you do your stuff

await release();

Be aware that the acquire may fail. There is a default 15000 ms timeout to try to acquire a mutex, with 1 attempt. Also, an acquired mutex lasts, by default, for 5 minutes. Which you can also change, like this:

const release = await client.acquire({
  id: 'my-mutex-id',
  waitTimeout: 30000, // will wait 30 seconds at each attempt of acquiring the mutex,
  attempts: 5 // will attempt up to 5 times to acquire the mutex,
  mutexTimeout: 60*60*1000 // the mutex will last for an hour if not released
});

// Here you do your stuff

await release();

License

Licensed under MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i grpc-mutex-client

Weekly Downloads

0

Version

0.3.1

License

MIT

Unpacked Size

11.7 kB

Total Files

15

Last publish

Collaborators

  • farenheith