Run npm/yarn install
npm install @devjoyvn/concurrency
import { ConcurrencyModule } from '@devjoyvn/concurrency';
import { Concurrency } from '@devjoyvn/concurrency';
@Module({
imports: [ConcurrencyModule.register('redis://localhost:6379')],
})
export class AppModule {}
@Concurrency({ key: 'test' })
public anyMethod(args) {
...
}
Pass a key generator function and anyMethod
arguments will be passed into the generator function automatically
@Concurrency({ key: (args: any) => `key_${args.customer.id}` })
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.
Devjoyvn (Github)
Licensed under the MIT License - see the LICENSE file for details.