better-lock 1.0.2 → 2.0.2-beta
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/.eslintrc.js +24 -0
- package/.idea/better-lock.iml +1 -7
- package/.idea/codeStyles/Project.xml +336 -5
- package/.idea/compiler.xml +7 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -2
- package/.idea/jsLibraryMappings.xml +0 -1
- package/.idea/markdown.xml +9 -0
- package/.idea/modules.xml +1 -1
- package/.idea/prettier.xml +8 -0
- package/.prettierrc.yaml +1 -3
- package/.travis.yml +2 -2
- package/README.md +113 -73
- package/dist/better_lock.d.ts +50 -0
- package/dist/better_lock.js +317 -0
- package/dist/better_lock.js.map +1 -0
- package/dist/errors.d.ts +44 -0
- package/dist/errors.js +131 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/internals.d.ts +75 -0
- package/dist/internals.js +75 -0
- package/dist/internals.js.map +1 -0
- package/dist/options.d.ts +54 -0
- package/dist/options.js +3 -0
- package/dist/options.js.map +1 -0
- package/dist/tools.d.ts +19 -0
- package/dist/tools.js +109 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/jest.config.js +4 -0
- package/package.json +32 -9
- package/spec/better_lock.spec.ts +614 -0
- package/src/better_lock.ts +430 -0
- package/src/errors.ts +124 -0
- package/src/index.ts +54 -0
- package/src/internals.ts +118 -0
- package/src/options.ts +63 -0
- package/src/tools.ts +111 -0
- package/src/types.ts +29 -0
- package/tsconfig.json +13 -0
- package/.idea/markdown-navigator/profiles_settings.xml +0 -3
- package/.idea/markdown-navigator.xml +0 -78
- package/.idea/misc.xml +0 -6
- package/.idea/watcherTasks.xml +0 -8
- package/index.js +0 -19
- package/spec/better_lock.spec.js +0 -602
- package/src/better_lock.js +0 -405
- package/src/errors.js +0 -81
- package/src/options.js +0 -104
- package/src/tools.js +0 -125
- package/src/types.js +0 -110
package/src/types.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Class that represents one scheduled job and its state. This is created every time user calls "acquire"
|
|
3
|
-
*/
|
|
4
|
-
class LockJob {
|
|
5
|
-
constructor(keys, executor, callback, options) {
|
|
6
|
-
LockJob._lastId++;
|
|
7
|
-
|
|
8
|
-
/** ID to uniquely identify this particular job */
|
|
9
|
-
this.id = LockJob._lastId;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* List of keys that will be locked. Always an array
|
|
13
|
-
* @type {Array}
|
|
14
|
-
*/
|
|
15
|
-
this.keys = keys;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Number of keys which this job is waiting on. Once this reaches 0, job will be executed
|
|
19
|
-
*/
|
|
20
|
-
this.waiting_count = keys.length;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Function that will be called inside the lock
|
|
24
|
-
*/
|
|
25
|
-
this.executor = executor;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Function that will be called once job is done, whether it succeeds or times out
|
|
29
|
-
*/
|
|
30
|
-
this.callback = callback;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Timestamp when job was created
|
|
34
|
-
*/
|
|
35
|
-
this.enqueued_at = new Date();
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Timestamp when job was executed
|
|
39
|
-
*/
|
|
40
|
-
this.executed_at = null;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* This is set when job ends, in case something holds a reference to it
|
|
44
|
-
*/
|
|
45
|
-
this.ended_at = null;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Options that apply to this particular job
|
|
49
|
-
* @type {LockJobOptions}
|
|
50
|
-
*/
|
|
51
|
-
this.options = options;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Id of the wait timer
|
|
55
|
-
*/
|
|
56
|
-
this.wait_timeout_id = null;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Id of the execution timer
|
|
60
|
-
*/
|
|
61
|
-
this.execution_timeout_id = null;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Saved incoming stack, for the purpose of extending stack traces
|
|
65
|
-
*/
|
|
66
|
-
this.incoming_stack = null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
toString() {
|
|
70
|
-
return `Job #${this.id} [${this.keys.join(', ')}]`;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
LockJob._lastId = 0;
|
|
75
|
-
|
|
76
|
-
// *********************************************************************************************************************
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Class to hold pending, holding and executing jobs for one key
|
|
80
|
-
*/
|
|
81
|
-
class KeyQueue {
|
|
82
|
-
constructor(key) {
|
|
83
|
-
this.key = key;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Queue of jobs waiting to be executed.
|
|
87
|
-
* Jobs in this state are governed by the wait_timeout.
|
|
88
|
-
* @type {LockJob[]}
|
|
89
|
-
*/
|
|
90
|
-
this.jobs = [];
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Active job that is holding this key. This job could be waiting on other keys or executing.
|
|
94
|
-
* @type {LockJob}
|
|
95
|
-
*/
|
|
96
|
-
this.active = null;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
toString() {
|
|
100
|
-
return this.key === KeyQueue.DEFAULT_QUEUE_KEY ? 'JobQueue' : `JobQueue<${this.key}>`;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// We will use this key when user doesn't supply anything
|
|
105
|
-
KeyQueue.DEFAULT_QUEUE_KEY = '___DEFAULT_QUEUE_KEY___';
|
|
106
|
-
|
|
107
|
-
module.exports = {
|
|
108
|
-
LockJob,
|
|
109
|
-
KeyQueue,
|
|
110
|
-
};
|