@saikatdutta1991/concurrency
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Concurrency

Distributed method level concurrency lock NestJS module backed by Redis

Installation

Run npm/yarn install

npm install @saikatdutta1991/concurrency

Imports

import { ConcurrencyModule } from '@saikatdutta1991/concurrency';
import { Concurrency } from '@saikatdutta1991/concurrency';

Register Module

@Module({
  imports: [ConcurrencyModule.register('redis://localhost:6379')],
})
export class AppModule {}

Usage

Assume we need to apply concurrency for given method

@Concurrency({ key: 'test' })
public anyMethod(args) {
...
}

Key Generator

Pass a key generator function and anyMethod arguments will be passed into the generator function automatically

@Concurrency({ key: (args: any) => `key_${args.customer.id}` })

Set Auto Lock Release Timeout

By default lock gets released after 30 seconds. To set custom auto lock release timeout.

@Concurrency({ key: 'test', autoReleaseAfterSeconds: 40 })

*Note: Lock gets released automacally after either function execution or timeout of default 30 seconds.

Author

Saikat Dutta (LinkedIn)

License

Licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

Package Sidebar

Install

npm i @saikatdutta1991/concurrency

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

14.4 kB

Total Files

21

Last publish

Collaborators

  • saikatdutta1991