0.1.4 • Published 7 years ago

sync-decorator v0.1.4

Weekly downloads
70
License
MIT
Repository
github
Last release
7 years ago

sync-decorator

NPM

Build Status Code Climate Test Coverage

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