Decorator to ensure that class method is not called by several callers simultaneously at the moment.
Install it via npm:
$ npm install --save sync-decorator
This module requires NodeJS 6.9 or higher.
Example code:
const test = new class Test {
@sync
method(attempt) {
console.log('executing', attempt);
return new Promise(resolve => setTimeout(
() => {
console.log('executed', attempt);
resolve();
},
1000
));
}
}
test.method(1);
test.method(2);
test.method(3);
Console output:
executing 1
executed 1
executing 2
executed 2
executing 3
executed 3
MIT