sync-decorator
v0.1.4
Published
Sync (mutex) class method decorator for ECMAScript.
Downloads
109
Maintainers
Readme
sync-decorator
Decorator to ensure that class method is not called by several callers simultaneously at the moment.
Installation
Install it via npm:
$ npm install --save sync-decorator
This module requires NodeJS 6.9 or higher.
Usage
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
License
MIT