@imqueue/rpc 1.14.0 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/decorators/lock.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
export interface LockOptions {
|
|
2
|
+
disabled?: boolean;
|
|
3
|
+
skipArgs?: number[];
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* \@lock() decorator implementation
|
|
3
7
|
* Will make all simultaneous similar method calls locked to be resolved with
|
|
4
8
|
* the first obtained values. Similarity is identified by a bypassed method
|
|
5
9
|
* argument values.
|
|
6
10
|
*
|
|
11
|
+
* @param {boolean|LockOptions} enabledOrOptions - whether to enable locks or not
|
|
7
12
|
* @return {(
|
|
8
13
|
* target: any,
|
|
9
14
|
* methodName: (string),
|
|
10
15
|
* descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
|
|
11
16
|
* ) => void}
|
|
12
17
|
*/
|
|
13
|
-
export declare function lock(
|
|
18
|
+
export declare function lock(enabledOrOptions?: boolean | LockOptions): (target: any, methodName: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => void;
|
package/src/decorators/lock.js
CHANGED
|
@@ -25,14 +25,21 @@ const __1 = require("..");
|
|
|
25
25
|
* the first obtained values. Similarity is identified by a bypassed method
|
|
26
26
|
* argument values.
|
|
27
27
|
*
|
|
28
|
+
* @param {boolean|LockOptions} enabledOrOptions - whether to enable locks or not
|
|
28
29
|
* @return {(
|
|
29
30
|
* target: any,
|
|
30
31
|
* methodName: (string),
|
|
31
32
|
* descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
|
|
32
33
|
* ) => void}
|
|
33
34
|
*/
|
|
34
|
-
function lock(
|
|
35
|
+
function lock(enabledOrOptions = true) {
|
|
35
36
|
return function (target, methodName, descriptor) {
|
|
37
|
+
const enabled = typeof enabledOrOptions === 'boolean'
|
|
38
|
+
? enabledOrOptions
|
|
39
|
+
: !enabledOrOptions.disabled;
|
|
40
|
+
const skipArgs = typeof enabledOrOptions === 'boolean'
|
|
41
|
+
? undefined
|
|
42
|
+
: enabledOrOptions.skipArgs;
|
|
36
43
|
const original = descriptor.value;
|
|
37
44
|
const className = typeof target === 'function'
|
|
38
45
|
? target.name // static
|
|
@@ -42,7 +49,7 @@ function lock(enabled = true) {
|
|
|
42
49
|
let lock;
|
|
43
50
|
let sig = '';
|
|
44
51
|
if (withLocks) {
|
|
45
|
-
sig = (0, __1.signature)(className, methodName, args);
|
|
52
|
+
sig = (0, __1.signature)(className, methodName, skipArgs ? args.filter((_, index) => !~skipArgs.indexOf(index)) : args);
|
|
46
53
|
lock = await __1.IMQLock.acquire(sig, undefined, {
|
|
47
54
|
className,
|
|
48
55
|
methodName,
|