Skip to content

Sync (mutex) class method decorator for ECMAScript.

License

Notifications You must be signed in to change notification settings

vladen/sync-decorator

Repository files navigation

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

About

Sync (mutex) class method decorator for ECMAScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published