better-lock 3.0.0 → 3.2.0

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 (40) hide show
  1. package/README.md +12 -3
  2. package/dist/better_lock.d.ts +13 -7
  3. package/dist/better_lock.js +80 -23
  4. package/dist/better_lock.js.map +1 -1
  5. package/dist/errors.d.ts +1 -0
  6. package/dist/errors.js +7 -1
  7. package/dist/errors.js.map +1 -1
  8. package/dist/options.d.ts +12 -0
  9. package/dist/types.d.ts +4 -0
  10. package/docs/assets/search.js +1 -1
  11. package/docs/classes/BetterLockError.html +3 -3
  12. package/docs/classes/BetterLockExecutionTimeoutError.html +6 -6
  13. package/docs/classes/BetterLockInternalError.html +3 -3
  14. package/docs/classes/BetterLockInvalidArgumentError.html +4 -4
  15. package/docs/classes/BetterLockJobAbortedError.html +5 -5
  16. package/docs/classes/BetterLockQueueOverflowError.html +8 -8
  17. package/docs/classes/BetterLockWaitTimeoutError.html +6 -6
  18. package/docs/classes/_internal_.BetterLock.html +189 -7
  19. package/docs/classes/_internal_.KeyQueue.html +4 -4
  20. package/docs/classes/_internal_.LockJob.html +13 -13
  21. package/docs/functions/_internal_.__home_panta_dev_pantas_better_lock_src_errors_.isAcquisitionFailureError.html +62 -0
  22. package/docs/index.html +13 -2
  23. package/docs/interfaces/BetterLockJobOptions.html +27 -4
  24. package/docs/interfaces/BetterLockOptions.html +26 -8
  25. package/docs/modules/_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html +6 -1
  26. package/docs/types/BetterLockErrorName.html +1 -1
  27. package/docs/types/BetterLockExecutor.html +1 -1
  28. package/docs/types/BetterLockKey.html +1 -1
  29. package/docs/types/BetterLockQueueEjectionStrategy.html +1 -1
  30. package/docs/types/_internal_.ICallback.html +1 -1
  31. package/docs/types/_internal_.ICallbackExecutor.html +1 -1
  32. package/docs/types/_internal_.IErrorExports.html +1 -1
  33. package/docs/types/_internal_.IPromiseExecutor.html +1 -1
  34. package/docs/variables/BetterLock.html +1 -1
  35. package/package.json +1 -1
  36. package/spec/better_lock.spec.ts +160 -0
  37. package/src/better_lock.ts +115 -31
  38. package/src/errors.ts +14 -1
  39. package/src/options.ts +15 -0
  40. package/src/types.ts +5 -0
package/docs/index.html CHANGED
@@ -87,6 +87,9 @@
87
87
  <li><code>jobOptions</code>: An object that should match interface <code>BetterLockJobOptions</code>. A subset of main options that will serve as overrides for this particular job (for example, timeout settings).</li>
88
88
  </ul>
89
89
  </li>
90
+ <li><p><code>BetterLock.acquireOr([key], failureResult, executor, [callback], [jobOptions])</code><br>The same as acquire, except if the lock can&#39;t be acquired (the executor never gets called), instead of throwing
91
+ an error, the lock will resolve/callback with the provided failureResult value (for example, a <code>null</code>).</p>
92
+ </li>
90
93
  <li><p><code>BetterLock.canAcquire([key])</code><br>Returns true if given key can be acquired.</p>
91
94
  </li>
92
95
  <li><p><code>BetterLock.abort([key])</code><br>Abort all jobs for a given key (or from the default job queue, if no key is given). Job executors will not be called. Callbacks will be called with <code>JobAbortedError</code>. Currently executing job will not be interrupted.</p>
@@ -112,8 +115,6 @@ If you do that, though, and you have a swallowed callback, the lock can remain l
112
115
  </li>
113
116
  <li><p><code>queue_size</code><br>Max queue size for waiting jobs.</p>
114
117
  </li>
115
- <li><p><code>queue_ejection_strategy</code><br>Which job to eject from the queue when it&#39;s full. Default is <code>newest</code>.</p>
116
- </li>
117
118
  </ul>
118
119
  <p>Default options are a static member <code>DEFAULT_OPTIONS</code> on the <code>BetterLock</code> class. During runtime, you can change the defaults like this:</p>
119
120
  <pre><code class="language-javascript"><span class="hl-5">import</span><span class="hl-0"> </span><span class="hl-6">BetterLock</span><span class="hl-0"> </span><span class="hl-5">from</span><span class="hl-0"> </span><span class="hl-7">&#39;better-lock&#39;</span><span class="hl-0">;</span><br/><br/><span class="hl-6">BetterLock</span><span class="hl-0">.</span><span class="hl-3">DEFAULT_OPTIONS</span><span class="hl-0">.</span><span class="hl-6">wait_timeout</span><span class="hl-0"> = </span><span class="hl-8">1000</span><span class="hl-0">;</span>
@@ -141,6 +142,16 @@ If you do that, though, and you have a swallowed callback, the lock can remain l
141
142
  <h3>Change log</h3>
142
143
  </a>
143
144
 
145
+ <a href="#320-20240621" id="320-20240621" style="color: inherit; text-decoration: none;">
146
+ <h4><strong>3.2.0</strong> (<em>2024/06/21</em>)</h4>
147
+ </a>
148
+ <p>Add new api <code>canAcquire</code>. A helper for &quot;best effort&quot; lock acquisition.</p>
149
+
150
+ <a href="#310-20240621" id="310-20240621" style="color: inherit; text-decoration: none;">
151
+ <h4><strong>3.1.0</strong> (<em>2024/06/21</em>)</h4>
152
+ </a>
153
+ <p>Add option <code>lock_condition</code>.</p>
154
+
144
155
  <a href="#300-20240418" id="300-20240418" style="color: inherit; text-decoration: none;">
145
156
  <h4><strong>3.0.0</strong> (<em>2024/04/18</em>)</h4>
146
157
  </a>
@@ -32,6 +32,10 @@
32
32
  <div class="tsd-index-list"><a href="BetterLockJobOptions.html#execution_timeout" class="tsd-index-link tsd-kind-property tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="#FF984D" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12" id="icon-1024-path"></rect><path d="M9.354 16V7.24H12.174C12.99 7.24 13.638 7.476 14.118 7.948C14.606 8.412 14.85 9.036 14.85 9.82C14.85 10.604 14.606 11.232 14.118 11.704C13.638 12.168 12.99 12.4 12.174 12.4H10.434V16H9.354ZM10.434 11.428H12.174C12.646 11.428 13.022 11.284 13.302 10.996C13.59 10.7 13.734 10.308 13.734 9.82C13.734 9.324 13.59 8.932 13.302 8.644C13.022 8.356 12.646 8.212 12.174 8.212H10.434V11.428Z" fill="var(--color-text)" id="icon-1024-text"></path></svg><span>execution_<wbr/>timeout</span></a>
33
33
  <a href="BetterLockJobOptions.html#extend_stack_traces" class="tsd-index-link tsd-kind-property tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg><span>extend_<wbr/>stack_<wbr/>traces</span></a>
34
34
  <a href="BetterLockJobOptions.html#wait_timeout" class="tsd-index-link tsd-kind-property tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg><span>wait_<wbr/>timeout</span></a>
35
+ </div></section>
36
+ <section class="tsd-index-section">
37
+ <h3 class="tsd-index-heading">Methods</h3>
38
+ <div class="tsd-index-list"><a href="BetterLockJobOptions.html#lock_condition" class="tsd-index-link tsd-kind-method tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="#FF4DB8" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12" id="icon-2048-path"></rect><path d="M9.162 16V7.24H10.578L11.514 10.072C11.602 10.328 11.674 10.584 11.73 10.84C11.794 11.088 11.842 11.28 11.874 11.416C11.906 11.28 11.954 11.088 12.018 10.84C12.082 10.584 12.154 10.324 12.234 10.06L13.122 7.24H14.538V16H13.482V12.82C13.482 12.468 13.49 12.068 13.506 11.62C13.53 11.172 13.558 10.716 13.59 10.252C13.622 9.78 13.654 9.332 13.686 8.908C13.726 8.476 13.762 8.1 13.794 7.78L12.366 12.16H11.334L9.894 7.78C9.934 8.092 9.97 8.456 10.002 8.872C10.042 9.28 10.078 9.716 10.11 10.18C10.142 10.636 10.166 11.092 10.182 11.548C10.206 12.004 10.218 12.428 10.218 12.82V16H9.162Z" fill="var(--color-text)" id="icon-2048-text"></path></svg><span>lock_<wbr/>condition</span></a>
35
39
  </div></section></div></details></section></section>
36
40
  <section class="tsd-panel-group tsd-member-group">
37
41
  <h2>Properties</h2>
@@ -41,21 +45,39 @@
41
45
  <div class="tsd-comment tsd-typography"><p>How long can a job be executing before timing out. Null to disable timeout. Overrides BetterLockOptions value.</p>
42
46
  </div><aside class="tsd-sources">
43
47
  <ul>
44
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L13">options.ts:13</a></li></ul></aside></section>
48
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L15">options.ts:15</a></li></ul></aside></section>
45
49
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="extend_stack_traces" class="tsd-anchor"></a>
46
50
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>extend_<wbr/>stack_<wbr/>traces</span><a href="#extend_stack_traces" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
47
51
  <div class="tsd-signature">extend_<wbr/>stack_<wbr/>traces<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span></div>
48
52
  <div class="tsd-comment tsd-typography"><p>In any error produced by BetterLock, extend the stack trace to include incoming trace. Overrides BetterLockOptions value.</p>
49
53
  </div><aside class="tsd-sources">
50
54
  <ul>
51
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L18">options.ts:18</a></li></ul></aside></section>
55
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L20">options.ts:20</a></li></ul></aside></section>
52
56
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="wait_timeout" class="tsd-anchor"></a>
53
57
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>wait_<wbr/>timeout</span><a href="#wait_timeout" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
54
58
  <div class="tsd-signature">wait_<wbr/>timeout<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div>
55
59
  <div class="tsd-comment tsd-typography"><p>How long can jobs wait in queue before timing out. Overrides BetterLockOptions value.</p>
56
60
  </div><aside class="tsd-sources">
57
61
  <ul>
58
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L8">options.ts:8</a></li></ul></aside></section></section></div>
62
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L10">options.ts:10</a></li></ul></aside></section></section>
63
+ <section class="tsd-panel-group tsd-member-group">
64
+ <h2>Methods</h2>
65
+ <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="lock_condition" class="tsd-anchor"></a>
66
+ <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>lock_<wbr/>condition</span><a href="#lock_condition" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
67
+ <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
68
+ <li class="tsd-signature" id="lock_condition.lock_condition-1">lock_<wbr/>condition<span class="tsd-signature-symbol">(</span>key<span class="tsd-signature-symbol">: </span><a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol"> | </span><a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul>
69
+ <ul class="tsd-descriptions">
70
+ <li class="tsd-description">
71
+ <div class="tsd-comment tsd-typography"><p>Before acquiring lock, call this function with the given key. If condition is rejected, the executor is immediately called, without locking.
72
+ This can be used to more conveniently opt out of locking, without duplicating or extracting the executor.
73
+ Overrides BetterLockOptions value.</p>
74
+ </div>
75
+ <div class="tsd-parameters">
76
+ <h4 class="tsd-parameters-title">Parameters</h4>
77
+ <ul class="tsd-parameter-list">
78
+ <li>
79
+ <h5>key: <a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol"> | </span><a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol">[]</span></h5></li></ul></div>
80
+ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section></section></div>
59
81
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
60
82
  <div class="tsd-navigation settings">
61
83
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -83,7 +105,8 @@
83
105
  <ul>
84
106
  <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockJobOptions.html#execution_timeout" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>execution_<wbr/>timeout</a></li>
85
107
  <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockJobOptions.html#extend_stack_traces" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>extend_<wbr/>stack_<wbr/>traces</a></li>
86
- <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockJobOptions.html#wait_timeout" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>wait_<wbr/>timeout</a></li></ul></li></ul></nav></div></div>
108
+ <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockJobOptions.html#wait_timeout" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>wait_<wbr/>timeout</a></li>
109
+ <li class="tsd-kind-method tsd-parent-kind-interface"><a href="BetterLockJobOptions.html#lock_condition" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-2048-path"></use><use href="#icon-2048-text"></use></svg>lock_<wbr/>condition</a></li></ul></li></ul></nav></div></div>
87
110
  <div class="container tsd-generator">
88
111
  <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
89
112
  <div class="overlay"></div><script src="../assets/main.js"></script></body></html>
@@ -39,7 +39,8 @@
39
39
  </div></section>
40
40
  <section class="tsd-index-section">
41
41
  <h3 class="tsd-index-heading">Methods</h3>
42
- <div class="tsd-index-list"><a href="BetterLockOptions.html#promise_tester" class="tsd-index-link tsd-kind-method tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="#FF4DB8" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12" id="icon-2048-path"></rect><path d="M9.162 16V7.24H10.578L11.514 10.072C11.602 10.328 11.674 10.584 11.73 10.84C11.794 11.088 11.842 11.28 11.874 11.416C11.906 11.28 11.954 11.088 12.018 10.84C12.082 10.584 12.154 10.324 12.234 10.06L13.122 7.24H14.538V16H13.482V12.82C13.482 12.468 13.49 12.068 13.506 11.62C13.53 11.172 13.558 10.716 13.59 10.252C13.622 9.78 13.654 9.332 13.686 8.908C13.726 8.476 13.762 8.1 13.794 7.78L12.366 12.16H11.334L9.894 7.78C9.934 8.092 9.97 8.456 10.002 8.872C10.042 9.28 10.078 9.716 10.11 10.18C10.142 10.636 10.166 11.092 10.182 11.548C10.206 12.004 10.218 12.428 10.218 12.82V16H9.162Z" fill="var(--color-text)" id="icon-2048-text"></path></svg><span>promise_<wbr/>tester</span></a>
42
+ <div class="tsd-index-list"><a href="BetterLockOptions.html#lock_condition" class="tsd-index-link tsd-kind-method tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="#FF4DB8" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12" id="icon-2048-path"></rect><path d="M9.162 16V7.24H10.578L11.514 10.072C11.602 10.328 11.674 10.584 11.73 10.84C11.794 11.088 11.842 11.28 11.874 11.416C11.906 11.28 11.954 11.088 12.018 10.84C12.082 10.584 12.154 10.324 12.234 10.06L13.122 7.24H14.538V16H13.482V12.82C13.482 12.468 13.49 12.068 13.506 11.62C13.53 11.172 13.558 10.716 13.59 10.252C13.622 9.78 13.654 9.332 13.686 8.908C13.726 8.476 13.762 8.1 13.794 7.78L12.366 12.16H11.334L9.894 7.78C9.934 8.092 9.97 8.456 10.002 8.872C10.042 9.28 10.078 9.716 10.11 10.18C10.142 10.636 10.166 11.092 10.182 11.548C10.206 12.004 10.218 12.428 10.218 12.82V16H9.162Z" fill="var(--color-text)" id="icon-2048-text"></path></svg><span>lock_<wbr/>condition</span></a>
43
+ <a href="BetterLockOptions.html#promise_tester" class="tsd-index-link tsd-kind-method tsd-parent-kind-interface"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-2048-path"></use><use href="#icon-2048-text"></use></svg><span>promise_<wbr/>tester</span></a>
43
44
  </div></section></div></details></section></section>
44
45
  <section class="tsd-panel-group tsd-member-group">
45
46
  <h2>Properties</h2>
@@ -51,7 +52,7 @@ If you do that, though, and you have a swallowed callback, the lock can remain l
51
52
  </div><aside class="tsd-sources">
52
53
  <p>Overrides <a href="BetterLockJobOptions.html">BetterLockJobOptions</a>.<a href="BetterLockJobOptions.html#execution_timeout">execution_timeout</a></p>
53
54
  <ul>
54
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L36">options.ts:36</a></li></ul></aside></section>
55
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L45">options.ts:45</a></li></ul></aside></section>
55
56
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="extend_stack_traces" class="tsd-anchor"></a>
56
57
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>extend_<wbr/>stack_<wbr/>traces</span><a href="#extend_stack_traces" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
57
58
  <div class="tsd-signature">extend_<wbr/>stack_<wbr/>traces<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span></div>
@@ -60,35 +61,35 @@ Defaults to true.</p>
60
61
  </div><aside class="tsd-sources">
61
62
  <p>Overrides <a href="BetterLockJobOptions.html">BetterLockJobOptions</a>.<a href="BetterLockJobOptions.html#extend_stack_traces">extend_stack_traces</a></p>
62
63
  <ul>
63
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L62">options.ts:62</a></li></ul></aside></section>
64
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L77">options.ts:77</a></li></ul></aside></section>
64
65
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="log" class="tsd-anchor"></a>
65
66
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>log</span><a href="#log" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
66
67
  <div class="tsd-signature">log<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">(</span>msg<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span></div>
67
68
  <div class="tsd-comment tsd-typography"><p>Whether to log the internal actions. Set to true to use console.log. Alternatively, provide your own function</p>
68
69
  </div><aside class="tsd-sources">
69
70
  <ul>
70
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L56">options.ts:56</a></li></ul></aside></section>
71
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L71">options.ts:71</a></li></ul></aside></section>
71
72
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="name" class="tsd-anchor"></a>
72
73
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>name</span><a href="#name" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
73
74
  <div class="tsd-signature">name<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span></div>
74
75
  <div class="tsd-comment tsd-typography"><p>Lock name. This will be written in all logs and error messages, to help you distinguish between different locks</p>
75
76
  </div><aside class="tsd-sources">
76
77
  <ul>
77
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L51">options.ts:51</a></li></ul></aside></section>
78
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L66">options.ts:66</a></li></ul></aside></section>
78
79
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="queue_ejection_strategy" class="tsd-anchor"></a>
79
80
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>queue_<wbr/>ejection_<wbr/>strategy</span><a href="#queue_ejection_strategy" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
80
81
  <div class="tsd-signature">queue_<wbr/>ejection_<wbr/>strategy<span class="tsd-signature-symbol">?:</span> <a href="../types/BetterLockQueueEjectionStrategy.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockQueueEjectionStrategy</a></div>
81
82
  <div class="tsd-comment tsd-typography"><p>If queue is full, which job to eject. Defaults to &#39;oldest&#39;.</p>
82
83
  </div><aside class="tsd-sources">
83
84
  <ul>
84
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L46">options.ts:46</a></li></ul></aside></section>
85
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L55">options.ts:55</a></li></ul></aside></section>
85
86
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="queue_size" class="tsd-anchor"></a>
86
87
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>queue_<wbr/>size</span><a href="#queue_size" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
87
88
  <div class="tsd-signature">queue_<wbr/>size<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div>
88
89
  <div class="tsd-comment tsd-typography"><p>Max queue size for waiting jobs.</p>
89
90
  </div><aside class="tsd-sources">
90
91
  <ul>
91
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L41">options.ts:41</a></li></ul></aside></section>
92
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L50">options.ts:50</a></li></ul></aside></section>
92
93
  <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="wait_timeout" class="tsd-anchor"></a>
93
94
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>wait_<wbr/>timeout</span><a href="#wait_timeout" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
94
95
  <div class="tsd-signature">wait_<wbr/>timeout<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div>
@@ -96,9 +97,25 @@ Defaults to true.</p>
96
97
  </div><aside class="tsd-sources">
97
98
  <p>Overrides <a href="BetterLockJobOptions.html">BetterLockJobOptions</a>.<a href="BetterLockJobOptions.html#wait_timeout">wait_timeout</a></p>
98
99
  <ul>
99
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L30">options.ts:30</a></li></ul></aside></section></section>
100
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L39">options.ts:39</a></li></ul></aside></section></section>
100
101
  <section class="tsd-panel-group tsd-member-group">
101
102
  <h2>Methods</h2>
103
+ <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="lock_condition" class="tsd-anchor"></a>
104
+ <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>lock_<wbr/>condition</span><a href="#lock_condition" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
105
+ <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
106
+ <li class="tsd-signature" id="lock_condition.lock_condition-1">lock_<wbr/>condition<span class="tsd-signature-symbol">(</span>key<span class="tsd-signature-symbol">: </span><a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol"> | </span><a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul>
107
+ <ul class="tsd-descriptions">
108
+ <li class="tsd-description">
109
+ <div class="tsd-comment tsd-typography"><p>Before acquiring lock, call this function with the given key. If condition is rejected, the executor is immediately called, without locking.
110
+ This can be used to more conveniently opt out of locking, without duplicating or extracting the executor.</p>
111
+ </div>
112
+ <div class="tsd-parameters">
113
+ <h4 class="tsd-parameters-title">Parameters</h4>
114
+ <ul class="tsd-parameter-list">
115
+ <li>
116
+ <h5>key: <a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol"> | </span><a href="../types/BetterLockKey.html" class="tsd-signature-type" data-tsd-kind="Type alias">BetterLockKey</a><span class="tsd-signature-symbol">[]</span></h5></li></ul></div>
117
+ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4><aside class="tsd-sources">
118
+ <p>Overrides <a href="BetterLockJobOptions.html">BetterLockJobOptions</a>.<a href="BetterLockJobOptions.html#lock_condition">lock_condition</a></p></aside></li></ul></section>
102
119
  <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="promise_tester" class="tsd-anchor"></a>
103
120
  <h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>promise_<wbr/>tester</span><a href="#promise_tester" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
104
121
  <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
@@ -147,6 +164,7 @@ you might want to tighten or loosen this bit.</p>
147
164
  <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockOptions.html#queue_ejection_strategy" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>queue_<wbr/>ejection_<wbr/>strategy</a></li>
148
165
  <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockOptions.html#queue_size" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>queue_<wbr/>size</a></li>
149
166
  <li class="tsd-kind-property tsd-parent-kind-interface"><a href="BetterLockOptions.html#wait_timeout" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-1024-path"></use><use href="#icon-1024-text"></use></svg>wait_<wbr/>timeout</a></li>
167
+ <li class="tsd-kind-method tsd-parent-kind-interface"><a href="BetterLockOptions.html#lock_condition" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-2048-path"></use><use href="#icon-2048-text"></use></svg>lock_<wbr/>condition</a></li>
150
168
  <li class="tsd-kind-method tsd-parent-kind-interface"><a href="BetterLockOptions.html#promise_tester" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-2048-path"></use><use href="#icon-2048-text"></use></svg>promise_<wbr/>tester</a></li></ul></li></ul></nav></div></div>
151
169
  <div class="container tsd-generator">
152
170
  <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
@@ -28,6 +28,10 @@
28
28
  <a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockJobAbortedError" class="tsd-index-link tsd-kind-reference tsd-parent-kind-namespace"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg><span>Better<wbr/>Lock<wbr/>Job<wbr/>Aborted<wbr/>Error</span></a>
29
29
  <a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockQueueOverflowError" class="tsd-index-link tsd-kind-reference tsd-parent-kind-namespace"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg><span>Better<wbr/>Lock<wbr/>Queue<wbr/>Overflow<wbr/>Error</span></a>
30
30
  <a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockWaitTimeoutError" class="tsd-index-link tsd-kind-reference tsd-parent-kind-namespace"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg><span>Better<wbr/>Lock<wbr/>Wait<wbr/>Timeout<wbr/>Error</span></a>
31
+ </div></section>
32
+ <section class="tsd-index-section">
33
+ <h3 class="tsd-index-heading">Functions</h3>
34
+ <div class="tsd-index-list"><a href="../functions/_internal_.__home_panta_dev_pantas_better_lock_src_errors_.isAcquisitionFailureError.html" class="tsd-index-link tsd-kind-function tsd-parent-kind-namespace"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-64-path"></rect><path d="M9.39 16V7.24H14.55V8.224H10.446V11.128H14.238V12.112H10.47V16H9.39Z" fill="var(--color-text)" id="icon-64-text"></path></svg><span>is<wbr/>Acquisition<wbr/>Failure<wbr/>Error</span></a>
31
35
  </div></section></div></details></section></section>
32
36
  <section class="tsd-panel-group tsd-member-group">
33
37
  <h2>References</h2>
@@ -74,7 +78,8 @@
74
78
  <li class="tsd-kind-reference tsd-parent-kind-namespace"><a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockInvalidArgumentError" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg>Better<wbr/>Lock<wbr/>Invalid<wbr/>Argument<wbr/>Error</a></li>
75
79
  <li class="tsd-kind-reference tsd-parent-kind-namespace"><a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockJobAbortedError" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg>Better<wbr/>Lock<wbr/>Job<wbr/>Aborted<wbr/>Error</a></li>
76
80
  <li class="tsd-kind-reference tsd-parent-kind-namespace"><a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockQueueOverflowError" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg>Better<wbr/>Lock<wbr/>Queue<wbr/>Overflow<wbr/>Error</a></li>
77
- <li class="tsd-kind-reference tsd-parent-kind-namespace"><a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockWaitTimeoutError" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg>Better<wbr/>Lock<wbr/>Wait<wbr/>Timeout<wbr/>Error</a></li></ul></nav></div></div>
81
+ <li class="tsd-kind-reference tsd-parent-kind-namespace"><a href="_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html#BetterLockWaitTimeoutError" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-8388608-path"></use><use href="#icon-8388608-text"></use></svg>Better<wbr/>Lock<wbr/>Wait<wbr/>Timeout<wbr/>Error</a></li>
82
+ <li class="tsd-kind-function tsd-parent-kind-namespace"><a href="../functions/_internal_.__home_panta_dev_pantas_better_lock_src_errors_.isAcquisitionFailureError.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-64-path"></use><use href="#icon-64-text"></use></svg>is<wbr/>Acquisition<wbr/>Failure<wbr/>Error</a></li></ul></nav></div></div>
78
83
  <div class="container tsd-generator">
79
84
  <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
80
85
  <div class="overlay"></div><script src="../assets/main.js"></script></body></html>
@@ -17,7 +17,7 @@
17
17
  <div class="tsd-comment tsd-typography"><p>All error names that we can emit</p>
18
18
  </div><aside class="tsd-sources">
19
19
  <ul>
20
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L8">types.ts:8</a></li></ul></aside></div>
20
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L8">types.ts:8</a></li></ul></aside></div>
21
21
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
22
22
  <div class="tsd-navigation settings">
23
23
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -19,7 +19,7 @@
19
19
  <li>
20
20
  <h4>TResult</h4></li></ul><aside class="tsd-sources">
21
21
  <ul>
22
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L24">types.ts:24</a></li></ul></aside></div>
22
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L24">types.ts:24</a></li></ul></aside></div>
23
23
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
24
24
  <div class="tsd-navigation settings">
25
25
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -17,7 +17,7 @@
17
17
  <div class="tsd-comment tsd-typography"><p>Key types that can be used for a lock.</p>
18
18
  </div><aside class="tsd-sources">
19
19
  <ul>
20
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L29">types.ts:29</a></li></ul></aside></div>
20
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L29">types.ts:29</a></li></ul></aside></div>
21
21
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
22
22
  <div class="tsd-navigation settings">
23
23
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -15,7 +15,7 @@
15
15
  <h1>Type alias BetterLockQueueEjectionStrategy</h1></div>
16
16
  <div class="tsd-signature">Better<wbr/>Lock<wbr/>Queue<wbr/>Ejection<wbr/>Strategy<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">&quot;oldest&quot;</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">&quot;newest&quot;</span></div><aside class="tsd-sources">
17
17
  <ul>
18
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/options.ts#L21">options.ts:21</a></li></ul></aside></div>
18
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/options.ts#L30">options.ts:30</a></li></ul></aside></div>
19
19
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
20
20
  <div class="tsd-navigation settings">
21
21
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -23,7 +23,7 @@ but also old-school callbacks, with varargs return values.</p>
23
23
  <li>
24
24
  <h4>TResult</h4></li></ul><aside class="tsd-sources">
25
25
  <ul>
26
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L14">types.ts:14</a></li></ul></aside></div>
26
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L14">types.ts:14</a></li></ul></aside></div>
27
27
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
28
28
  <div class="tsd-navigation settings">
29
29
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -37,7 +37,7 @@ It can either accept a done() function, or return a promise.</p>
37
37
  <h5>lockDone: <a href="_internal_.ICallback.html" class="tsd-signature-type" data-tsd-kind="Type alias">ICallback</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type" data-tsd-kind="Type parameter">TResult</span><span class="tsd-signature-symbol">&gt;</span></h5></li></ul></div>
38
38
  <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources">
39
39
  <ul>
40
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L22">types.ts:22</a></li></ul></aside></div>
40
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L22">types.ts:22</a></li></ul></aside></div>
41
41
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
42
42
  <div class="tsd-navigation settings">
43
43
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -16,7 +16,7 @@
16
16
  <h1>Type alias IErrorExports</h1></div>
17
17
  <div class="tsd-signature">IError<wbr/>Exports<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">typeof </span><a href="../modules/_internal_.__home_panta_dev_pantas_better_lock_src_errors_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&quot;/home/panta/dev/pantas/better-lock/src/errors&quot;</a></div><aside class="tsd-sources">
18
18
  <ul>
19
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L3">types.ts:3</a></li></ul></aside></div>
19
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L3">types.ts:3</a></li></ul></aside></div>
20
20
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
21
21
  <div class="tsd-navigation settings">
22
22
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -29,7 +29,7 @@
29
29
  <li class="tsd-description">
30
30
  <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type" data-tsd-kind="Type parameter">TResult</span><span class="tsd-signature-symbol">&gt;</span></h4></li></ul></li></ul></div><aside class="tsd-sources">
31
31
  <ul>
32
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/types.ts#L23">types.ts:23</a></li></ul></aside></div>
32
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/types.ts#L23">types.ts:23</a></li></ul></aside></div>
33
33
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
34
34
  <div class="tsd-navigation settings">
35
35
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
@@ -15,7 +15,7 @@
15
15
  <h1>Variable BetterLock<code class="tsd-tag ts-flagConst">Const</code> </h1></div>
16
16
  <div class="tsd-signature">Better<wbr/>Lock<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">typeof </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../classes/_internal_.BetterLock.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLock</a><span class="tsd-signature-symbol"> &amp; </span><span class="tsd-signature-symbol">{ </span>BetterLock<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../classes/_internal_.BetterLock.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLock</a><span class="tsd-signature-symbol">; </span>Error<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockError</a><span class="tsd-signature-symbol">; </span>ExecutionTimeoutError<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockExecutionTimeoutError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockExecutionTimeoutError</a><span class="tsd-signature-symbol">; </span>InternalError<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockInternalError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockInternalError</a><span class="tsd-signature-symbol">; </span>InvalidArgumentError<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockInvalidArgumentError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockInvalidArgumentError</a><span class="tsd-signature-symbol">; </span>JobAbortedError<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockJobAbortedError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockJobAbortedError</a><span class="tsd-signature-symbol">; </span>QueueOverflowError<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockQueueOverflowError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockQueueOverflowError</a><span class="tsd-signature-symbol">; </span>WaitTimeoutError<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/BetterLockWaitTimeoutError.html" class="tsd-signature-type" data-tsd-kind="Class">BetterLockWaitTimeoutError</a><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol"> = ...</span></div><aside class="tsd-sources">
17
17
  <ul>
18
- <li>Defined in <a href="https://github.com/panta82/better-lock/blob/336aa4f/src/index.ts#L43">index.ts:43</a></li></ul></aside></div>
18
+ <li>Defined in <a href="https://github.com/panta82/better-lock/blob/91aeb2b/src/index.ts#L43">index.ts:43</a></li></ul></aside></div>
19
19
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
20
20
  <div class="tsd-navigation settings">
21
21
  <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-lock",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "A (better) node.js lock library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import BetterLock from '../src/index';
2
2
  import { LockJob } from '../src/internals';
3
+ import { ILockJobOptions } from '../src/options';
3
4
 
4
5
  describe('BetterLock', () => {
5
6
  let baseDefaultOptions;
@@ -626,6 +627,165 @@ describe('BetterLock', () => {
626
627
  });
627
628
  });
628
629
  });
630
+
631
+ describe('will respect lock_condition', () => {
632
+ function runJob(
633
+ lock: InstanceType<typeof BetterLock>,
634
+ key: string,
635
+ expectedMs: number,
636
+ options?: ILockJobOptions
637
+ ) {
638
+ const startedAt = new Date();
639
+ let executed = false;
640
+ return lock
641
+ .acquire(
642
+ key,
643
+ () => {
644
+ executed = true;
645
+ expectMs(new Date().valueOf() - startedAt.valueOf(), expectedMs);
646
+ return waitPromise(50);
647
+ },
648
+ options
649
+ )
650
+ .finally(() => {
651
+ expect(executed).toBeTruthy();
652
+ });
653
+ }
654
+
655
+ it('for global condition', async () => {
656
+ const lock = new BetterLock({
657
+ lock_condition: key => !String(key).startsWith('a'),
658
+ });
659
+
660
+ await Promise.all([
661
+ runJob(lock, 'a', 0),
662
+ runJob(lock, 'a', 0),
663
+ runJob(lock, 'a', 0),
664
+ runJob(lock, 'b', 0),
665
+ runJob(lock, 'b', 50),
666
+ runJob(lock, 'b', 100),
667
+ ]);
668
+ });
669
+
670
+ it('for local condition', async () => {
671
+ const lock = new BetterLock({
672
+ lock_condition: key => !String(key).startsWith('a'),
673
+ });
674
+
675
+ const overrideToB = {
676
+ lock_condition: key => !String(key).startsWith('b'),
677
+ };
678
+
679
+ await Promise.all([
680
+ runJob(lock, 'b', 0, overrideToB),
681
+ runJob(lock, 'b', 0, overrideToB),
682
+ runJob(lock, 'b', 0, overrideToB),
683
+ runJob(lock, 'a', 0, overrideToB),
684
+ runJob(lock, 'a', 50, overrideToB),
685
+ runJob(lock, 'a', 100, overrideToB),
686
+ ]);
687
+ });
688
+ });
689
+
690
+ describe('acquireOr', () => {
691
+ describe('will correctly handle failureResults', () => {
692
+ it('from QueueOverflowError', testDone => {
693
+ const lock = new BetterLock({
694
+ wait_timeout: 200, // should never trigger
695
+ execution_timeout: 300, // should never trigger
696
+ queue_size: 2,
697
+ });
698
+
699
+ let cbCount = 0;
700
+ lock.acquireOr(0, waitCallback(25, null, 1), (err, res) => {
701
+ // The executing one
702
+ cbCount++;
703
+ expect(cbCount).toEqual(2);
704
+ expect(err).toBeNull();
705
+ expect(res).toEqual(1);
706
+ });
707
+ lock.acquireOr(0, waitCallback(5, null, 2), (err, res) => {
708
+ // This is the one that will get kicked out
709
+ cbCount++;
710
+ expect(cbCount).toEqual(1);
711
+ expect(err).toBeNull();
712
+ expect(res).toEqual(0);
713
+ });
714
+ lock.acquireOr(0, waitCallback(5, null, 3), (err, res) => {
715
+ cbCount++;
716
+ expect(cbCount).toEqual(3);
717
+ expect(err).toBeNull();
718
+ expect(res).toEqual(3);
719
+ testDone();
720
+ });
721
+ lock.acquireOr(0, waitCallback(5, null, 4), (err, res) => {
722
+ // This one will trigger the kicking out.
723
+ cbCount++;
724
+ expect(cbCount).toEqual(4);
725
+ expect(err).toBeNull();
726
+ expect(res).toEqual(4);
727
+ });
728
+ });
729
+
730
+ it('from WaitTimeoutError', async () => {
731
+ const lock = new BetterLock({
732
+ wait_timeout: 50,
733
+ execution_timeout: 100, // should never trigger
734
+ });
735
+
736
+ const promise1 = lock.acquireOr('fail1', waitCallback(75, null, 'ok1'));
737
+ const promise2 = lock.acquireOr('fail2', waitCallback(200000, null, 'ok2'));
738
+
739
+ // Enqueue after some time, this one should run
740
+ await waitPromise(50);
741
+ const promise3 = lock.acquireOr('fail3', waitCallback(50, null, 'ok3'));
742
+
743
+ const results = await Promise.all([promise1, promise2, promise3]);
744
+
745
+ expect(results).toEqual(['ok1', 'fail2', 'ok3']);
746
+ });
747
+
748
+ it('from AbortedError', async () => {
749
+ const lock = new BetterLock();
750
+
751
+ let noCallCount = 0;
752
+ const noCall = () => {
753
+ noCallCount++;
754
+ };
755
+
756
+ let cbCount = 0;
757
+ const callback = (err, res) => {
758
+ cbCount++;
759
+ expect(err).toBeNull();
760
+ expect(res).toEqual('fail');
761
+ };
762
+
763
+ lock.acquireOr('fail', noCall, callback);
764
+ lock.acquireOr('a', 'fail', noCall, callback);
765
+ lock.acquireOr('b', 'fail', noCall, callback);
766
+
767
+ lock.abortAll();
768
+
769
+ expect(lock.canAcquire()).toBeTruthy();
770
+ expect(lock.canAcquire('a')).toBeTruthy();
771
+ expect(lock.canAcquire('b')).toBeTruthy();
772
+ expect(noCallCount).toEqual(0);
773
+ expect(cbCount).toEqual(3);
774
+ });
775
+ });
776
+
777
+ it('will correctly pass other errors ', async () => {
778
+ const lock = new BetterLock({
779
+ execution_timeout: 10,
780
+ });
781
+
782
+ await expect(
783
+ lock.acquireOr('fail', async () => {
784
+ await waitPromise(20); // Should cause ExecutionTimeoutError.
785
+ })
786
+ ).rejects.toBeInstanceOf(BetterLock.ExecutionTimeoutError);
787
+ });
788
+ });
629
789
  });
630
790
 
631
791
  function waitCallback(ms: number, ...args): (done: (...args: any) => void) => void {