@@ -31,6 +31,8 @@ export class Mutex implements Synchronizer {
31
31
/**
32
32
* Locks this mutex
33
33
*
34
+ * [lockWith]{@link lockWith} is the preferred choice.
35
+ *
34
36
* @throws {ConcurrencyInterruptedException } when the mutex is interrupted
35
37
* @returns a promise when the lock has been set
36
38
*/
@@ -43,6 +45,8 @@ export class Mutex implements Synchronizer {
43
45
*
44
46
* Throws an error if the given time exceeds
45
47
*
48
+ * [tryLockWith]{@link tryLockWith} is the preferred choice.
49
+ *
46
50
* @param timeout maximum time (in ms) to lock
47
51
* @throws {ConcurrencyExceedTimeoutException } when the time limit exceeds
48
52
* @throws {ConcurrencyInterruptedException } when the mutex is interrupted
@@ -54,11 +58,39 @@ export class Mutex implements Synchronizer {
54
58
55
59
/**
56
60
* Unlocks this mutex
61
+ *
62
+ * [lockWith]{@link lockWith} or [tryLockWith]{@link tryLockWith} are the preferred choices.
57
63
*/
58
64
public unlock ( ) {
59
65
this . semaphore . release ( ) ;
60
66
}
61
67
68
+ /**
69
+ * Locks this mutex and run the critical section function
70
+ * Then, automatically unlocks it.
71
+ *
72
+ * @param cs function to run once the locked is acquired (critical section)
73
+ * @throws {ConcurrencyInterruptedException } when the mutex is interrupted
74
+ * @returns a Promise after the mutex locked and unlocked and what has been return from `fn`
75
+ */
76
+ public lockWith < T = void > ( cs : ( ) => Promise < T > | T ) : Promise < T > {
77
+ return Promise . reject ( new Error ( "Not implemented" ) ) ;
78
+ }
79
+
80
+ /**
81
+ * Locks this mutex within a time limit and run the critical section function
82
+ * Then, automatically unlocks it.
83
+ *
84
+ * @param timeout maximum time (in ms) to lock
85
+ * @param cs function to run once the locked is acquired (critical section)
86
+ * @throws {ConcurrencyExceedTimeoutException } when the time limit exceeds
87
+ * @throws {ConcurrencyInterruptedException } when the mutex is interrupted
88
+ * @returns a Promise after the mutex locked and unlocked and what has been return from `fn`
89
+ */
90
+ public tryLockWith < T = void > ( timeout : number , cs : ( ) => Promise < T > | T ) : Promise < T > {
91
+ return Promise . reject ( new Error ( "Not implemented" ) ) ;
92
+ }
93
+
62
94
/**
63
95
* Interrupts all awaiting "Threads" with an [exception]{@link ConcurrencyInterruptedException}.
64
96
*
0 commit comments