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.
Files changed (55) hide show
  1. package/.eslintrc.js +24 -0
  2. package/.idea/better-lock.iml +1 -7
  3. package/.idea/codeStyles/Project.xml +336 -5
  4. package/.idea/compiler.xml +7 -0
  5. package/.idea/inspectionProfiles/Project_Default.xml +6 -2
  6. package/.idea/jsLibraryMappings.xml +0 -1
  7. package/.idea/markdown.xml +9 -0
  8. package/.idea/modules.xml +1 -1
  9. package/.idea/prettier.xml +8 -0
  10. package/.prettierrc.yaml +1 -3
  11. package/.travis.yml +2 -2
  12. package/README.md +113 -73
  13. package/dist/better_lock.d.ts +50 -0
  14. package/dist/better_lock.js +317 -0
  15. package/dist/better_lock.js.map +1 -0
  16. package/dist/errors.d.ts +44 -0
  17. package/dist/errors.js +131 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/index.d.ts +16 -0
  20. package/dist/index.js +28 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/internals.d.ts +75 -0
  23. package/dist/internals.js +75 -0
  24. package/dist/internals.js.map +1 -0
  25. package/dist/options.d.ts +54 -0
  26. package/dist/options.js +3 -0
  27. package/dist/options.js.map +1 -0
  28. package/dist/tools.d.ts +19 -0
  29. package/dist/tools.js +109 -0
  30. package/dist/tools.js.map +1 -0
  31. package/dist/types.d.ts +23 -0
  32. package/dist/types.js +3 -0
  33. package/dist/types.js.map +1 -0
  34. package/jest.config.js +4 -0
  35. package/package.json +32 -9
  36. package/spec/better_lock.spec.ts +614 -0
  37. package/src/better_lock.ts +430 -0
  38. package/src/errors.ts +124 -0
  39. package/src/index.ts +54 -0
  40. package/src/internals.ts +118 -0
  41. package/src/options.ts +63 -0
  42. package/src/tools.ts +111 -0
  43. package/src/types.ts +29 -0
  44. package/tsconfig.json +13 -0
  45. package/.idea/markdown-navigator/profiles_settings.xml +0 -3
  46. package/.idea/markdown-navigator.xml +0 -78
  47. package/.idea/misc.xml +0 -6
  48. package/.idea/watcherTasks.xml +0 -8
  49. package/index.js +0 -19
  50. package/spec/better_lock.spec.js +0 -602
  51. package/src/better_lock.js +0 -405
  52. package/src/errors.js +0 -81
  53. package/src/options.js +0 -104
  54. package/src/tools.js +0 -125
  55. 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
- };