/
ISharedTimedLockable.ts
109 lines (105 loc) · 5.35 KB
/
ISharedTimedLockable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
import { ISharedLockable } from "./ISharedLockable";
/**
* Common interface for shared & timed lockable mutex.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ISharedTimedLockable extends ISharedLockable
{
/* ---------------------------------------------------------
WRITE LOCK
--------------------------------------------------------- */
/**
* Tries to write lock the mutex until timeout.
*
* Attempts to monopoly a mutex until timeout. If succeeded to monopoly the mutex until the
* timeout, it returns `true`. Otherwise failed to acquiring the lock in the given time, the
* function gives up the trial and returns `false`.
*
* Failed to acquiring the lock in the given time (returns `false`), it means that there's
* someone who has already {@link lock monopolied} or {@link lock_shared shared} the mutex and
* does not return it over the timeout.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* or {@link lock_shared share} the mutex would be fall into the forever sleep. Therefore,
* never forget to calling the {@link unlock} function or utilize the
* {@link UniqueLock.try_lock_for} function instead to ensure the safety.
*
* @param ms The maximum miliseconds for waiting.
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock_for(ms: number): Promise<boolean>;
/**
* Tries to write lock the mutex until time expiration.
*
* Attemps to monopoly a mutex until time expiration. If succeeded to monopoly the mutex
* until the time expiration, it returns `true`. Otherwise failed to acquiring the lock in the
* given time, the function gives up the trial and returns `false`.
*
* Failed to acquiring the lock in the given time (returns `false`), it means that there's
* someone who has already {@link lock monopolied} or {@link lock_shared shared} the mutex and
* does not return it over the time expiration.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* or {@link lock_shared share} the mutex would be fall into the forever sleep. Therefore,
* never forget to calling the {@link unlock} function or utilize the
* {@link UniqueLock.try_lock_until} function instead to ensure the safety.
*
* @param at The maximum time point to wait.
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock_until(at: Date): Promise<boolean>;
/* ---------------------------------------------------------
READ LOCK
--------------------------------------------------------- */
/**
* Tries to read lock the mutex until timeout.
*
* Attemps to share a mutex until timeout. If succeeded to share the mutex until timeout, it
* returns `true`. Otherwise failed to acquiring the shared lock in the given time, the
* function gives up the trial and returns `false`.
*
* Failed to acquring the shared lock in the given time (returns `false`), it means that
* there's someone who has already {@link lock monopolied} the mutex and does not return it
* over the timeout.
*
* Note that, if you succeeded to share the mutex (returns `true`) but do not call the
* {@link unlock_shared} function after your buinsess, the others who want to
* {@link lock monopoly} the mutex would be fall into the forever sleep. Therefore, never
* forget to calling the {@link unlock_shared} function or utilize the
* {@link SharedLock.try_lock_for} function instead to ensure the safety.
*
* @param ms The maximum miliseconds for waiting.
* @return Whether succeeded to share the mutex or not.
*/
try_lock_shared_for(ms: number): Promise<boolean>;
/**
* Tries to read lock the mutex until time expiration.
*
* Attemps to share a mutex until time expiration. If succeeded to share the mutex until time
* expiration, it returns `true`. Otherwise failed to acquiring the shared lock in the given
* time, the function gives up the trial and returns `false`.
*
* Failed to acquring the shared lock in the given time (returns `false`), it means that
* there's someone who has already {@link lock monopolied} the mutex and does not return it
* over the time expiration.
*
* Note that, if you succeeded to share the mutex (returns `true`) but do not call the
* {@link unlock_shared} function after your buinsess, the others who want to
* {@link lock monopoly} the mutex would be fall into the forever sleep. Therefore, never
* forget to calling the {@link unlock_shared} function or utilize the
* {@link SharedLock.try_lock_until} function instead to ensure the safety.
*
* @param at The maximum time point to wait.
* @return Whether succeeded to share the mutex or not.
*/
try_lock_shared_until(at: Date): Promise<boolean>;
}