@daiso-tech/core 0.24.0 → 0.26.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.
- package/README.md +3 -2
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +12 -3
- package/dist/async/utilities/lazy-promise/lazy-promise.js +37 -4
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +4 -4
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +4 -4
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +5 -5
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +70 -184
- package/dist/cache/implementations/derivables/cache/cache.js +68 -185
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +11 -15
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +0 -11
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +5 -5
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +5 -5
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.js +5 -5
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_shared.d.ts +0 -7
- package/dist/event-bus/contracts/_shared.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +6 -5
- package/dist/event-bus/contracts/event-bus.contract.d.ts +21 -16
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +4 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +4 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +4 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +64 -33
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +92 -33
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +957 -201
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/lock-provider.contract.d.ts +2 -2
- package/dist/lock/contracts/lock.contract.d.ts +24 -6
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +2 -2
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +2 -2
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +90 -48
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +67 -43
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +4 -23
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +8 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +744 -11
- package/dist/lock/implementations/derivables/lock-provider/lock.js +770 -3
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +36 -5
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +10 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +1 -0
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +417 -0
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.js +4 -4
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/utilities/{constants.js → _constants.js} +1 -1
- package/dist/utilities/_constants.js.map +1 -0
- package/dist/utilities/_module-exports.d.ts +1 -1
- package/dist/utilities/_module-exports.js +1 -1
- package/dist/utilities/_module-exports.js.map +1 -1
- package/dist/utilities/contracts/_module.d.ts +0 -1
- package/dist/utilities/contracts/_module.js +0 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/functions.d.ts +3 -7
- package/dist/utilities/functions.js +3 -10
- package/dist/utilities/functions.js.map +1 -1
- package/dist/utilities/pipeline/_module.d.ts +1 -0
- package/dist/utilities/pipeline/_module.js +2 -0
- package/dist/utilities/pipeline/_module.js.map +1 -0
- package/dist/utilities/pipeline/pipeline.d.ts +45 -0
- package/dist/utilities/pipeline/pipeline.js +75 -0
- package/dist/utilities/pipeline/pipeline.js.map +1 -0
- package/dist/utilities/time-span/time-span.d.ts +3 -12
- package/dist/utilities/time-span/time-span.js +3 -6
- package/dist/utilities/time-span/time-span.js.map +1 -1
- package/dist/utilities/types.d.ts +19 -2
- package/package.json +1 -1
- package/dist/utilities/constants.js.map +0 -1
- package/dist/utilities/contracts/buildable.contract.d.ts +0 -11
- package/dist/utilities/contracts/buildable.contract.js +0 -5
- package/dist/utilities/contracts/buildable.contract.js.map +0 -1
- /package/dist/utilities/{constants.d.ts → _constants.d.ts} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { TimeSpan, type OneOrMore } from "../../../../utilities/_module-exports.js";
|
|
4
|
+
import { TimeSpan, type Invokable, type OneOrMore } from "../../../../utilities/_module-exports.js";
|
|
5
5
|
import type { IDatabaseLockAdapter, LockEvents } from "../../../../lock/contracts/_module-exports.js";
|
|
6
6
|
import { type ILock, type IGroupableLockProvider, type LockProviderCreateSettings, type ILockProvider, type ILockAdapter } from "../../../../lock/contracts/_module-exports.js";
|
|
7
7
|
import type { BackoffPolicy, LazyPromise, RetryPolicy } from "../../../../async/_module-exports.js";
|
|
8
|
-
import type { EventClass, EventInstance, IGroupableEventBus,
|
|
8
|
+
import type { EventClass, EventInstance, IGroupableEventBus, Unsubscribe } from "../../../../event-bus/contracts/_module-exports.js";
|
|
9
9
|
import type { IFlexibleSerde } from "../../../../serde/contracts/_module-exports.js";
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -20,17 +20,45 @@ export type LockProviderSettings = {
|
|
|
20
20
|
adapter: ILockAdapter | IDatabaseLockAdapter;
|
|
21
21
|
serde: OneOrMore<IFlexibleSerde>;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* @default
|
|
24
|
+
* ```ts
|
|
25
|
+
* new EventBus({
|
|
26
|
+
* adapter: new MemoryEventBusAdapter({
|
|
27
|
+
* rootGroup: "@global"
|
|
28
|
+
* })
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
24
31
|
*/
|
|
25
32
|
eventBus?: IGroupableEventBus<any>;
|
|
26
33
|
/**
|
|
27
34
|
* You can decide the default ttl value for <i>{@link ILock}</i> expiration. If null is passed then no ttl will be used by default.
|
|
28
|
-
* @default
|
|
35
|
+
* @default
|
|
36
|
+
* ```ts
|
|
37
|
+
* TimeSpan.fromMinutes(5);
|
|
38
|
+
* ```
|
|
29
39
|
*/
|
|
30
40
|
defaultTtl?: TimeSpan | null;
|
|
41
|
+
/**
|
|
42
|
+
* The default refresh time used in the <i>{@link ILock}</i> <i>acquireBlocking</i> and <i>runBlocking</i> methods.
|
|
43
|
+
* @default
|
|
44
|
+
* ```ts
|
|
45
|
+
* TimeSpan.fromSeconds(1);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
defaultBlockingInterval?: TimeSpan;
|
|
49
|
+
/**
|
|
50
|
+
* The default refresh time used in the <i>{@link ILock}</i> <i>acquireBlocking</i> and <i>runBlocking</i> methods.
|
|
51
|
+
* @default
|
|
52
|
+
* ```ts
|
|
53
|
+
* TimeSpan.fromMinutes(1);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
defaultBlockingTime?: TimeSpan;
|
|
31
57
|
/**
|
|
32
58
|
* The default refresh time used in the <i>{@link ILock}</i> <i>extend</i> method.
|
|
33
|
-
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* TimeSpan.fromMinutes(5);
|
|
61
|
+
* ```
|
|
34
62
|
*/
|
|
35
63
|
defaultRefreshTime?: TimeSpan;
|
|
36
64
|
/**
|
|
@@ -72,6 +100,8 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
72
100
|
private readonly createOwnerId;
|
|
73
101
|
private readonly adapter;
|
|
74
102
|
private readonly defaultTtl;
|
|
103
|
+
private readonly defaultBlockingInterval;
|
|
104
|
+
private readonly defaultBlockingTime;
|
|
75
105
|
private readonly defaultRefreshTime;
|
|
76
106
|
private readonly retryAttempts;
|
|
77
107
|
private readonly backoffPolicy;
|
|
@@ -107,16 +137,16 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
107
137
|
constructor(settings: LockProviderSettings);
|
|
108
138
|
private registerToSerde;
|
|
109
139
|
/**
|
|
110
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
140
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
111
141
|
*
|
|
112
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
113
|
-
* Refer to <i>{@link
|
|
142
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
143
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
114
144
|
* @example
|
|
115
145
|
* ```ts
|
|
116
146
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
117
147
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
118
148
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
119
|
-
* import type {
|
|
149
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
120
150
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
121
151
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
122
152
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -134,24 +164,26 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
134
164
|
* eventBus,
|
|
135
165
|
* });
|
|
136
166
|
*
|
|
137
|
-
* const listener:
|
|
167
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
138
168
|
* console.log(event);
|
|
139
169
|
* }
|
|
140
170
|
* await lockProvider.addListener(KeyAcquiredLockEvent, listener);
|
|
171
|
+
* await lockProvider.removeListener(KeyAcquiredLockEvent, listener);
|
|
172
|
+
* await lockProvider.create("a").acquire();
|
|
141
173
|
* ```
|
|
142
174
|
*/
|
|
143
|
-
addListener<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener:
|
|
175
|
+
addListener<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
144
176
|
/**
|
|
145
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
177
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
146
178
|
*
|
|
147
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
148
|
-
* Refer to <i>{@link
|
|
179
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
180
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
149
181
|
* @example
|
|
150
182
|
* ```ts
|
|
151
183
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
152
184
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
153
185
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
154
|
-
* import type {
|
|
186
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
155
187
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
156
188
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
157
189
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -169,24 +201,26 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
169
201
|
* eventBus,
|
|
170
202
|
* });
|
|
171
203
|
*
|
|
172
|
-
* const listener:
|
|
204
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
173
205
|
* console.log(event);
|
|
174
206
|
* }
|
|
175
207
|
* await lockProvider.addListenerMany([KeyAcquiredLockEvent], listener);
|
|
208
|
+
* await lockProvider.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
209
|
+
* await lockProvider.create("a").acquire();
|
|
176
210
|
* ```
|
|
177
211
|
*/
|
|
178
|
-
addListenerMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener:
|
|
212
|
+
addListenerMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
179
213
|
/**
|
|
180
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
214
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
181
215
|
*
|
|
182
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
183
|
-
* Refer to <i>{@link
|
|
216
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
217
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
184
218
|
* @example
|
|
185
219
|
* ```ts
|
|
186
220
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
187
221
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
188
222
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
189
|
-
* import type {
|
|
223
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
190
224
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
191
225
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
192
226
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -204,24 +238,26 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
204
238
|
* eventBus,
|
|
205
239
|
* });
|
|
206
240
|
*
|
|
207
|
-
* const listener:
|
|
241
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
208
242
|
* console.log(event);
|
|
209
243
|
* }
|
|
244
|
+
* await lockProvider.addListener(KeyAcquiredLockEvent, listener);
|
|
210
245
|
* await lockProvider.removeListener(KeyAcquiredLockEvent, listener);
|
|
246
|
+
* await lockProvider.create("a").acquire();
|
|
211
247
|
* ```
|
|
212
248
|
*/
|
|
213
|
-
removeListener<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener:
|
|
249
|
+
removeListener<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
214
250
|
/**
|
|
215
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
251
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
216
252
|
*
|
|
217
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
218
|
-
* Refer to <i>{@link
|
|
253
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
254
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
219
255
|
* @example
|
|
220
256
|
* ```ts
|
|
221
257
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
222
258
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
223
259
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
224
|
-
* import type {
|
|
260
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
225
261
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
226
262
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
227
263
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -239,24 +275,26 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
239
275
|
* eventBus,
|
|
240
276
|
* });
|
|
241
277
|
*
|
|
242
|
-
* const listener:
|
|
278
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
243
279
|
* console.log(event);
|
|
244
280
|
* }
|
|
281
|
+
* await lockProvider.addListenerMany(KeyAcquiredLockEvent, listener);
|
|
245
282
|
* await lockProvider.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
283
|
+
* await lockProvider.create("a").acquire();
|
|
246
284
|
* ```
|
|
247
285
|
*/
|
|
248
|
-
removeListenerMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener:
|
|
286
|
+
removeListenerMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
249
287
|
/**
|
|
250
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
288
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
251
289
|
*
|
|
252
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
253
|
-
* Refer to <i>{@link
|
|
290
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
291
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
254
292
|
* @example
|
|
255
293
|
* ```ts
|
|
256
294
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
257
295
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
258
296
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
259
|
-
* import type {
|
|
297
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
260
298
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
261
299
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
262
300
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -274,24 +312,26 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
274
312
|
* eventBus,
|
|
275
313
|
* });
|
|
276
314
|
*
|
|
277
|
-
* const listener:
|
|
315
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
278
316
|
* console.log(event);
|
|
279
317
|
* }
|
|
280
318
|
* await lockProvider.listenOnce(KeyAcquiredLockEvent, listener);
|
|
319
|
+
* await lockProvider.create("a").acquire();
|
|
281
320
|
* ```
|
|
282
321
|
*/
|
|
283
|
-
listenOnce<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener:
|
|
322
|
+
listenOnce<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
323
|
+
asPromise<TEventClass extends EventClass<LockEvents>>(event: TEventClass): LazyPromise<EventInstance<TEventClass>>;
|
|
284
324
|
/**
|
|
285
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
325
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
286
326
|
*
|
|
287
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
288
|
-
* Refer to <i>{@link
|
|
327
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
328
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
289
329
|
* @example
|
|
290
330
|
* ```ts
|
|
291
331
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
292
332
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
293
333
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
294
|
-
* import type {
|
|
334
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
295
335
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
296
336
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
297
337
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -309,25 +349,26 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
309
349
|
* eventBus,
|
|
310
350
|
* });
|
|
311
351
|
*
|
|
312
|
-
* const listener:
|
|
352
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
313
353
|
* console.log(event);
|
|
314
354
|
* }
|
|
315
355
|
* const unsubscribe = await lockProvider.subscribe(KeyAcquiredLockEvent, listener);
|
|
356
|
+
* await lockProvider.create("a").acquire();
|
|
316
357
|
* await unsubscribe();
|
|
317
358
|
* ```
|
|
318
359
|
*/
|
|
319
|
-
subscribe<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener:
|
|
360
|
+
subscribe<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
|
|
320
361
|
/**
|
|
321
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
362
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
322
363
|
*
|
|
323
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
324
|
-
* Refer to <i>{@link
|
|
364
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
365
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
325
366
|
* @example
|
|
326
367
|
* ```ts
|
|
327
368
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
328
369
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
329
370
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
330
|
-
* import type {
|
|
371
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
331
372
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
332
373
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
333
374
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -345,14 +386,15 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
345
386
|
* eventBus,
|
|
346
387
|
* });
|
|
347
388
|
*
|
|
348
|
-
* const listener:
|
|
389
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
349
390
|
* console.log(event);
|
|
350
391
|
* }
|
|
351
392
|
* const unsubscribe = await lockProvider.subscribeMany([KeyAcquiredLockEvent], listener);
|
|
393
|
+
* await lockProvider.create("a").acquire();
|
|
352
394
|
* await unsubscribe();
|
|
353
395
|
* ```
|
|
354
396
|
*/
|
|
355
|
-
subscribeMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener:
|
|
397
|
+
subscribeMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
|
|
356
398
|
/**
|
|
357
399
|
* ```ts
|
|
358
400
|
* import type { IGroupableLockProvider } from "@daiso-tech/core/lock/contracts";
|
|
@@ -385,7 +427,7 @@ export declare class LockProvider implements IGroupableLockProvider {
|
|
|
385
427
|
* });
|
|
386
428
|
*
|
|
387
429
|
* // You can provide a custom owner. By default the owner will be unique random value.
|
|
388
|
-
* const
|
|
430
|
+
* const lockC = lockProvider.create("b", {
|
|
389
431
|
* owner: "user-1"
|
|
390
432
|
* });
|
|
391
433
|
* ```
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { CORE,
|
|
4
|
+
import { CORE, resolveOneOrMoreStr, TimeSpan, } from "../../../../utilities/_module-exports.js";
|
|
5
5
|
import {} from "../../../../lock/contracts/_module-exports.js";
|
|
6
6
|
import { Lock } from "../../../../lock/implementations/derivables/lock-provider/lock.js";
|
|
7
7
|
import { EventBus } from "../../../../event-bus/implementations/derivables/_module-exports.js";
|
|
8
|
-
import {
|
|
8
|
+
import { MemoryEventBusAdapter } from "../../../../event-bus/implementations/adapters/_module-exports.js";
|
|
9
9
|
import { v4 } from "uuid";
|
|
10
10
|
import { DatabaseLockAdapter } from "../../../../lock/implementations/derivables/lock-provider/database-lock-adapter.js";
|
|
11
11
|
import { LockSerdeTransformer } from "../../../../lock/implementations/derivables/lock-provider/lock-serde-transformer.js";
|
|
@@ -47,6 +47,8 @@ export class LockProvider {
|
|
|
47
47
|
createOwnerId;
|
|
48
48
|
adapter;
|
|
49
49
|
defaultTtl;
|
|
50
|
+
defaultBlockingInterval;
|
|
51
|
+
defaultBlockingTime;
|
|
50
52
|
defaultRefreshTime;
|
|
51
53
|
retryAttempts;
|
|
52
54
|
backoffPolicy;
|
|
@@ -80,8 +82,10 @@ export class LockProvider {
|
|
|
80
82
|
* ```
|
|
81
83
|
*/
|
|
82
84
|
constructor(settings) {
|
|
83
|
-
const { createOwnerId = () => v4(), adapter, defaultTtl = LockProvider.DEFAULT_TTL, defaultRefreshTime = LockProvider.DEFAULT_REFRESH_TIME, retryAttempts = null, backoffPolicy = null, retryPolicy = null, timeout = null, eventBus = new EventBus({
|
|
84
|
-
adapter: new
|
|
85
|
+
const { createOwnerId = () => v4(), adapter, defaultTtl = LockProvider.DEFAULT_TTL, defaultBlockingInterval = TimeSpan.fromSeconds(1), defaultBlockingTime = TimeSpan.fromMinutes(1), defaultRefreshTime = LockProvider.DEFAULT_REFRESH_TIME, retryAttempts = null, backoffPolicy = null, retryPolicy = null, timeout = null, eventBus = new EventBus({
|
|
86
|
+
adapter: new MemoryEventBusAdapter({
|
|
87
|
+
rootGroup: "@global",
|
|
88
|
+
}),
|
|
85
89
|
}), serde, } = settings;
|
|
86
90
|
this.createOwnerId = createOwnerId;
|
|
87
91
|
if (LockProvider.isDatabaseAdapter(adapter)) {
|
|
@@ -92,6 +96,8 @@ export class LockProvider {
|
|
|
92
96
|
}
|
|
93
97
|
this.serde = serde;
|
|
94
98
|
this.defaultTtl = defaultTtl ?? LockProvider.DEFAULT_TTL;
|
|
99
|
+
this.defaultBlockingInterval = defaultBlockingInterval;
|
|
100
|
+
this.defaultBlockingTime = defaultBlockingTime;
|
|
95
101
|
this.defaultRefreshTime = defaultRefreshTime;
|
|
96
102
|
this.retryAttempts = retryAttempts;
|
|
97
103
|
this.backoffPolicy = backoffPolicy;
|
|
@@ -103,6 +109,8 @@ export class LockProvider {
|
|
|
103
109
|
}
|
|
104
110
|
registerToSerde() {
|
|
105
111
|
const transformer = new LockSerdeTransformer({
|
|
112
|
+
defaultBlockingInterval: this.defaultBlockingInterval,
|
|
113
|
+
defaultBlockingTime: this.defaultBlockingTime,
|
|
106
114
|
adapter: this.adapter,
|
|
107
115
|
backoffPolicy: this.backoffPolicy,
|
|
108
116
|
defaultRefreshTime: this.defaultRefreshTime,
|
|
@@ -120,16 +128,16 @@ export class LockProvider {
|
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
/**
|
|
123
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
131
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
124
132
|
*
|
|
125
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
126
|
-
* Refer to <i>{@link
|
|
133
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
134
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
127
135
|
* @example
|
|
128
136
|
* ```ts
|
|
129
137
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
130
138
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
131
139
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
132
|
-
* import type {
|
|
140
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
133
141
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
134
142
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
135
143
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -147,26 +155,28 @@ export class LockProvider {
|
|
|
147
155
|
* eventBus,
|
|
148
156
|
* });
|
|
149
157
|
*
|
|
150
|
-
* const listener:
|
|
158
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
151
159
|
* console.log(event);
|
|
152
160
|
* }
|
|
153
161
|
* await lockProvider.addListener(KeyAcquiredLockEvent, listener);
|
|
162
|
+
* await lockProvider.removeListener(KeyAcquiredLockEvent, listener);
|
|
163
|
+
* await lockProvider.create("a").acquire();
|
|
154
164
|
* ```
|
|
155
165
|
*/
|
|
156
166
|
addListener(event, listener) {
|
|
157
167
|
return this.lockProviderEventBus.addListener(event, listener);
|
|
158
168
|
}
|
|
159
169
|
/**
|
|
160
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
170
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
161
171
|
*
|
|
162
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
163
|
-
* Refer to <i>{@link
|
|
172
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
173
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
164
174
|
* @example
|
|
165
175
|
* ```ts
|
|
166
176
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
167
177
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
168
178
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
169
|
-
* import type {
|
|
179
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
170
180
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
171
181
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
172
182
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -184,26 +194,28 @@ export class LockProvider {
|
|
|
184
194
|
* eventBus,
|
|
185
195
|
* });
|
|
186
196
|
*
|
|
187
|
-
* const listener:
|
|
197
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
188
198
|
* console.log(event);
|
|
189
199
|
* }
|
|
190
200
|
* await lockProvider.addListenerMany([KeyAcquiredLockEvent], listener);
|
|
201
|
+
* await lockProvider.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
202
|
+
* await lockProvider.create("a").acquire();
|
|
191
203
|
* ```
|
|
192
204
|
*/
|
|
193
205
|
addListenerMany(events, listener) {
|
|
194
206
|
return this.lockProviderEventBus.addListenerMany(events, listener);
|
|
195
207
|
}
|
|
196
208
|
/**
|
|
197
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
209
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
198
210
|
*
|
|
199
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
200
|
-
* Refer to <i>{@link
|
|
211
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
212
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
201
213
|
* @example
|
|
202
214
|
* ```ts
|
|
203
215
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
204
216
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
205
217
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
206
|
-
* import type {
|
|
218
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
207
219
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
208
220
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
209
221
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -221,26 +233,28 @@ export class LockProvider {
|
|
|
221
233
|
* eventBus,
|
|
222
234
|
* });
|
|
223
235
|
*
|
|
224
|
-
* const listener:
|
|
236
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
225
237
|
* console.log(event);
|
|
226
238
|
* }
|
|
239
|
+
* await lockProvider.addListener(KeyAcquiredLockEvent, listener);
|
|
227
240
|
* await lockProvider.removeListener(KeyAcquiredLockEvent, listener);
|
|
241
|
+
* await lockProvider.create("a").acquire();
|
|
228
242
|
* ```
|
|
229
243
|
*/
|
|
230
244
|
removeListener(event, listener) {
|
|
231
245
|
return this.lockProviderEventBus.removeListener(event, listener);
|
|
232
246
|
}
|
|
233
247
|
/**
|
|
234
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
248
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
235
249
|
*
|
|
236
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
237
|
-
* Refer to <i>{@link
|
|
250
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
251
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
238
252
|
* @example
|
|
239
253
|
* ```ts
|
|
240
254
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
241
255
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
242
256
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
243
|
-
* import type {
|
|
257
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
244
258
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
245
259
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
246
260
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -258,26 +272,28 @@ export class LockProvider {
|
|
|
258
272
|
* eventBus,
|
|
259
273
|
* });
|
|
260
274
|
*
|
|
261
|
-
* const listener:
|
|
275
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
262
276
|
* console.log(event);
|
|
263
277
|
* }
|
|
278
|
+
* await lockProvider.addListenerMany(KeyAcquiredLockEvent, listener);
|
|
264
279
|
* await lockProvider.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
280
|
+
* await lockProvider.create("a").acquire();
|
|
265
281
|
* ```
|
|
266
282
|
*/
|
|
267
283
|
removeListenerMany(events, listener) {
|
|
268
284
|
return this.lockProviderEventBus.removeListenerMany(events, listener);
|
|
269
285
|
}
|
|
270
286
|
/**
|
|
271
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
287
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
272
288
|
*
|
|
273
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
274
|
-
* Refer to <i>{@link
|
|
289
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
290
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
275
291
|
* @example
|
|
276
292
|
* ```ts
|
|
277
293
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
278
294
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
279
295
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
280
|
-
* import type {
|
|
296
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
281
297
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
282
298
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
283
299
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -295,26 +311,30 @@ export class LockProvider {
|
|
|
295
311
|
* eventBus,
|
|
296
312
|
* });
|
|
297
313
|
*
|
|
298
|
-
* const listener:
|
|
314
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
299
315
|
* console.log(event);
|
|
300
316
|
* }
|
|
301
317
|
* await lockProvider.listenOnce(KeyAcquiredLockEvent, listener);
|
|
318
|
+
* await lockProvider.create("a").acquire();
|
|
302
319
|
* ```
|
|
303
320
|
*/
|
|
304
321
|
listenOnce(event, listener) {
|
|
305
322
|
return this.lockProviderEventBus.listenOnce(event, listener);
|
|
306
323
|
}
|
|
324
|
+
asPromise(event) {
|
|
325
|
+
return this.lockProviderEventBus.asPromise(event);
|
|
326
|
+
}
|
|
307
327
|
/**
|
|
308
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
328
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
309
329
|
*
|
|
310
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
311
|
-
* Refer to <i>{@link
|
|
330
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
331
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
312
332
|
* @example
|
|
313
333
|
* ```ts
|
|
314
334
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
315
335
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
316
336
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
317
|
-
* import type {
|
|
337
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
318
338
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
319
339
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
320
340
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -332,10 +352,11 @@ export class LockProvider {
|
|
|
332
352
|
* eventBus,
|
|
333
353
|
* });
|
|
334
354
|
*
|
|
335
|
-
* const listener:
|
|
355
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
336
356
|
* console.log(event);
|
|
337
357
|
* }
|
|
338
358
|
* const unsubscribe = await lockProvider.subscribe(KeyAcquiredLockEvent, listener);
|
|
359
|
+
* await lockProvider.create("a").acquire();
|
|
339
360
|
* await unsubscribe();
|
|
340
361
|
* ```
|
|
341
362
|
*/
|
|
@@ -343,16 +364,16 @@ export class LockProvider {
|
|
|
343
364
|
return this.lockProviderEventBus.subscribe(event, listener);
|
|
344
365
|
}
|
|
345
366
|
/**
|
|
346
|
-
* You listen to different events of all locks created by <i>LockProvider</i> class.
|
|
367
|
+
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
347
368
|
*
|
|
348
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>
|
|
349
|
-
* Refer to <i>{@link
|
|
369
|
+
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
370
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
350
371
|
* @example
|
|
351
372
|
* ```ts
|
|
352
373
|
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
353
374
|
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
354
375
|
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
355
|
-
* import type {
|
|
376
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
356
377
|
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
357
378
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
358
379
|
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
@@ -370,10 +391,11 @@ export class LockProvider {
|
|
|
370
391
|
* eventBus,
|
|
371
392
|
* });
|
|
372
393
|
*
|
|
373
|
-
* const listener:
|
|
394
|
+
* const listener: Invokable<LockEvents> = event => {
|
|
374
395
|
* console.log(event);
|
|
375
396
|
* }
|
|
376
397
|
* const unsubscribe = await lockProvider.subscribeMany([KeyAcquiredLockEvent], listener);
|
|
398
|
+
* await lockProvider.create("a").acquire();
|
|
377
399
|
* await unsubscribe();
|
|
378
400
|
* ```
|
|
379
401
|
*/
|
|
@@ -412,7 +434,7 @@ export class LockProvider {
|
|
|
412
434
|
* });
|
|
413
435
|
*
|
|
414
436
|
* // You can provide a custom owner. By default the owner will be unique random value.
|
|
415
|
-
* const
|
|
437
|
+
* const lockC = lockProvider.create("b", {
|
|
416
438
|
* owner: "user-1"
|
|
417
439
|
* });
|
|
418
440
|
* ```
|
|
@@ -420,12 +442,14 @@ export class LockProvider {
|
|
|
420
442
|
create(key, settings = {}) {
|
|
421
443
|
const { ttl = this.defaultTtl, owner = this.createOwnerId() } = settings;
|
|
422
444
|
return new Lock({
|
|
445
|
+
defaultBlockingInterval: this.defaultBlockingInterval,
|
|
446
|
+
defaultBlockingTime: this.defaultBlockingTime,
|
|
423
447
|
lockProviderEventDispatcher: this.lockProviderEventBus,
|
|
424
448
|
lockEventBus: this.eventBus,
|
|
425
449
|
adapter: this.adapter,
|
|
426
450
|
defaultRefreshTime: this.defaultRefreshTime,
|
|
427
|
-
key:
|
|
428
|
-
owner:
|
|
451
|
+
key: resolveOneOrMoreStr(key),
|
|
452
|
+
owner: resolveOneOrMoreStr(owner),
|
|
429
453
|
ttl,
|
|
430
454
|
lazyPromiseSettings: {
|
|
431
455
|
backoffPolicy: this.backoffPolicy,
|
|
@@ -501,7 +525,7 @@ export class LockProvider {
|
|
|
501
525
|
*/
|
|
502
526
|
withGroup(group) {
|
|
503
527
|
return new LockProvider({
|
|
504
|
-
adapter: this.adapter.withGroup(
|
|
528
|
+
adapter: this.adapter.withGroup(resolveOneOrMoreStr(group)),
|
|
505
529
|
eventBus: this.eventBus,
|
|
506
530
|
defaultTtl: this.defaultTtl,
|
|
507
531
|
defaultRefreshTime: this.defaultRefreshTime,
|