@daiso-tech/core 0.31.0 → 0.32.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/dist/async/_module-exports.d.ts +1 -0
- package/dist/async/_module-exports.js +1 -0
- package/dist/async/_module-exports.js.map +1 -1
- package/dist/async/async.events.d.ts +82 -0
- package/dist/async/async.events.js +59 -0
- package/dist/async/async.events.js.map +1 -0
- package/dist/async/utilities/lazy-promise/lazy-promise-event-bus.d.ts +15 -0
- package/dist/async/utilities/lazy-promise/lazy-promise-event-bus.js +50 -0
- package/dist/async/utilities/lazy-promise/lazy-promise-event-bus.js.map +1 -0
- package/dist/async/utilities/lazy-promise/lazy-promise-listener.contract.d.ts +23 -0
- package/dist/async/utilities/lazy-promise/lazy-promise-listener.contract.js +44 -0
- package/dist/async/utilities/lazy-promise/lazy-promise-listener.contract.js.map +1 -0
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +101 -51
- package/dist/async/utilities/lazy-promise/lazy-promise.js +155 -96
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/retry/retry-or-fail.d.ts +1 -1
- package/dist/async/utilities/retry/retry-or-fail.js +1 -1
- package/dist/async/utilities/retry/retry-or-fail.js.map +1 -1
- package/dist/async/utilities/retry/retry.d.ts +1 -1
- package/dist/async/utilities/retry/retry.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache/cache.d.ts +20 -159
- package/dist/cache/implementations/derivables/cache/cache.js +14 -174
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +11 -32
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +10 -52
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +5 -5
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +5 -5
- package/dist/collection/implementations/_shared.d.ts +2 -0
- package/dist/collection/implementations/_shared.js +2 -0
- package/dist/collection/implementations/_shared.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +5 -8
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +5 -19
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +5 -5
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +5 -5
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +18 -13
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +14 -33
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +9 -35
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +8 -54
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/lock/contracts/lock.contract.d.ts +4 -4
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +1 -2
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +1 -2
- 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 +47 -24
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +40 -40
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +0 -204
- package/dist/lock/implementations/derivables/lock-provider/lock.js +0 -204
- 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 +11 -37
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +10 -59
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +1 -2
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +1 -2
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +0 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +0 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +7 -7
- package/dist/serde/implementations/derivables/serde.js +7 -7
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +0 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +0 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js.map +1 -1
- package/dist/utilities/classes/_module.d.ts +1 -0
- package/dist/utilities/classes/_module.js +1 -0
- package/dist/utilities/classes/_module.js.map +1 -1
- package/dist/utilities/classes/sync-event-bus/_module.d.ts +1 -0
- package/dist/utilities/classes/sync-event-bus/_module.js +2 -0
- package/dist/utilities/classes/sync-event-bus/_module.js.map +1 -0
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.d.ts +16 -0
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js +53 -0
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js.map +1 -0
- package/dist/utilities/contracts/_module.d.ts +1 -0
- package/dist/utilities/contracts/_module.js +1 -0
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/sync-event-bus-listenable.d.ts +13 -0
- package/dist/utilities/contracts/sync-event-bus-listenable.js +5 -0
- package/dist/utilities/contracts/sync-event-bus-listenable.js.map +1 -0
- package/dist/utilities/functions/invokable.d.ts +4 -0
- package/dist/utilities/functions/invokable.js +9 -0
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Async
|
|
3
|
-
*/
|
|
4
1
|
import { retryOrFail } from "../../../async/utilities/retry/_module.js";
|
|
5
2
|
import { timeoutAndFail } from "../../../async/utilities/timeout/_module.js";
|
|
6
3
|
import { abortAndFail } from "../../../async/utilities/abort/_module.js";
|
|
7
4
|
import {
|
|
8
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
TimeoutAsyncError,
|
|
6
|
+
TimeoutAsyncError, } from "../../../async/async.errors.js";
|
|
7
|
+
import {
|
|
12
8
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
9
|
RetryAsyncError, } from "../../../async/async.errors.js";
|
|
14
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
AbortAsyncError, } from "../../../async/async.errors.js";
|
|
13
|
+
import { removeUndefinedProperties, resolveAsyncLazyable, resolveInvokable, SyncEventBus, } from "../../../utilities/_module-exports.js";
|
|
15
14
|
import { delay } from "../../../async/utilities/_module.js";
|
|
15
|
+
import { AbortAsyncEvent, FailureAsyncEvent, FinallyAsyncEvent, RetryAttemptAsyncEvent, RetryFailureAsyncEvent, RetryTimeoutAsyncEvent, SuccessAsyncEvent, TotalTimeoutFailureAsyncEvent, } from "../../../async/async.events.js";
|
|
16
16
|
/**
|
|
17
17
|
* The <i>LazyPromise</i> class is used for creating lazy <i>{@link PromiseLike}<i> object that will only execute when awaited or when then method is called.
|
|
18
18
|
* The class includes helpful methods
|
|
19
19
|
* - <i>defer</i>
|
|
20
|
-
* - <i>
|
|
21
|
-
* - <i>
|
|
22
|
-
* - <i>
|
|
23
|
-
* - <i>
|
|
24
|
-
* - <i>
|
|
20
|
+
* - <i>setRetryAttempts</i>
|
|
21
|
+
* - <i>setRetryTimeout</i>
|
|
22
|
+
* - <i>setRetryPolicy</i>
|
|
23
|
+
* - <i>setBackoffPolicy</i>
|
|
24
|
+
* - <i>setTotalTimeout</i>
|
|
25
|
+
* - <i>setAbortSignal</i>
|
|
25
26
|
*
|
|
26
27
|
* The order in which these methods are called does not affect their methodality. Internally, the following execution order is applied:
|
|
27
|
-
* 1. <i>
|
|
28
|
-
* 2. <i>
|
|
29
|
-
* 3. <i>
|
|
28
|
+
* 1. <i>setRetryTimeout</i>
|
|
29
|
+
* 2. <i>setRetryAttempts</i>
|
|
30
|
+
* 3. <i>setTotalTimeout</i>
|
|
31
|
+
* 4. <i>setAbortSignal</i>
|
|
30
32
|
*
|
|
31
33
|
* This means that combining all methods ensures the <i>retryAttempts</i> method will continue retrying even if the timeout is triggered,
|
|
32
34
|
* while the <i>abort</i> method takes priority to cancel all operations if activated.
|
|
@@ -36,7 +38,7 @@ import { delay } from "../../../async/utilities/_module.js";
|
|
|
36
38
|
*/
|
|
37
39
|
export class LazyPromise {
|
|
38
40
|
/**
|
|
39
|
-
* The <i>wrapFn</i> is convience method used for wrapping
|
|
41
|
+
* The <i>wrapFn</i> is convience method used for wrapping async <i>{@link Invokable}</i> with a <i>LazyPromise</i>.
|
|
40
42
|
* @example
|
|
41
43
|
* ```ts
|
|
42
44
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -47,7 +49,7 @@ export class LazyPromise {
|
|
|
47
49
|
*
|
|
48
50
|
* const file = await readFile("none_existing_file.txt")
|
|
49
51
|
* .setRetryAttempts(4)
|
|
50
|
-
* .
|
|
52
|
+
* .setRetryTimeout(TimeSpan.fromMinutes(1));
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
53
55
|
static wrapFn(fn, settings) {
|
|
@@ -66,6 +68,7 @@ export class LazyPromise {
|
|
|
66
68
|
* console.log("a");
|
|
67
69
|
* await LazyPromise.delay(TimeSpan.fromSeconds(2));
|
|
68
70
|
* console.log("b");
|
|
71
|
+
* ```
|
|
69
72
|
*/
|
|
70
73
|
static delay(time) {
|
|
71
74
|
return new LazyPromise(async () => {
|
|
@@ -75,30 +78,56 @@ export class LazyPromise {
|
|
|
75
78
|
/**
|
|
76
79
|
* The <i>all<i> method works similarly to <i>{@link Promise.all}</i> with the key distinction that it operates lazily.
|
|
77
80
|
*/
|
|
78
|
-
static all(promises) {
|
|
79
|
-
return new LazyPromise(async () => Promise.all(promises));
|
|
81
|
+
static all(promises, settings) {
|
|
82
|
+
return new LazyPromise(async () => Promise.all(promises), settings);
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* The <i>allSettled<i> method works similarly to <i>{@link Promise.allSettled}</i> with the key distinction that it operates lazily.
|
|
83
86
|
*/
|
|
84
|
-
static allSettled(promises) {
|
|
85
|
-
return new LazyPromise(async () => Promise.allSettled(promises));
|
|
87
|
+
static allSettled(promises, settings) {
|
|
88
|
+
return new LazyPromise(async () => Promise.allSettled(promises), settings);
|
|
86
89
|
}
|
|
87
90
|
/**
|
|
88
91
|
* The <i>race<i> method works similarly to <i>{@link Promise.race}</i> with the key distinction that it operates lazily.
|
|
89
92
|
*/
|
|
90
|
-
static race(promises) {
|
|
91
|
-
return new LazyPromise(async () => Promise.race(promises));
|
|
93
|
+
static race(promises, settings) {
|
|
94
|
+
return new LazyPromise(async () => Promise.race(promises), settings);
|
|
92
95
|
}
|
|
93
96
|
/**
|
|
94
97
|
* The <i>any<i> method works similarly to <i>{@link Promise.any}</i> with the key distinction that it operates lazily.
|
|
95
98
|
*/
|
|
96
|
-
static any(promises) {
|
|
97
|
-
return new LazyPromise(async () => Promise.any(promises));
|
|
99
|
+
static any(promises, settings) {
|
|
100
|
+
return new LazyPromise(async () => Promise.any(promises), settings);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The <i>fromCallback</i> is convience method used for wrapping Node js callback functions with a <i>LazyPromise</i>.
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
107
|
+
* import { readFile } from "node:fs";
|
|
108
|
+
*
|
|
109
|
+
* const lazyPromise = LazyPromise.fromCallback<Buffer>((resolve, reject) => {
|
|
110
|
+
* readFile("FILE_PATH", (err, data) => {
|
|
111
|
+
* if (err !== null) {
|
|
112
|
+
* reject(err);
|
|
113
|
+
* return;
|
|
114
|
+
* }
|
|
115
|
+
* resolve(data);
|
|
116
|
+
* });
|
|
117
|
+
* });
|
|
118
|
+
* const file = await lazyPromise;
|
|
119
|
+
* console.log(file);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
static fromCallback(callback, settings) {
|
|
123
|
+
return new LazyPromise(() => new Promise((resolve, reject) => {
|
|
124
|
+
callback(resolve, reject);
|
|
125
|
+
}), settings);
|
|
98
126
|
}
|
|
99
127
|
promise = null;
|
|
100
128
|
asyncFn;
|
|
101
129
|
settings;
|
|
130
|
+
eventBus = new SyncEventBus();
|
|
102
131
|
/**
|
|
103
132
|
* @example
|
|
104
133
|
* ```ts
|
|
@@ -110,9 +139,12 @@ export class LazyPromise {
|
|
|
110
139
|
*
|
|
111
140
|
* // "I am lazy" will only logged when awaited or then method i called.
|
|
112
141
|
* await promise;
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* You can pass sync or async <i>{@link Invokable}</i>.
|
|
113
145
|
*/
|
|
114
|
-
constructor(
|
|
115
|
-
this.asyncFn = () => resolveAsyncLazyable(
|
|
146
|
+
constructor(invokable, settings = {}) {
|
|
147
|
+
this.asyncFn = () => resolveAsyncLazyable(invokable);
|
|
116
148
|
this.settings = removeUndefinedProperties({
|
|
117
149
|
retryAttempts: null,
|
|
118
150
|
backoffPolicy: null,
|
|
@@ -126,16 +158,30 @@ export class LazyPromise {
|
|
|
126
158
|
...settings,
|
|
127
159
|
});
|
|
128
160
|
}
|
|
161
|
+
addListener(event, listener) {
|
|
162
|
+
this.eventBus.addListener(event, listener);
|
|
163
|
+
}
|
|
164
|
+
removeListener(event, listener) {
|
|
165
|
+
this.eventBus.removeListener(event, listener);
|
|
166
|
+
}
|
|
129
167
|
applyRetryTimeout() {
|
|
130
168
|
if (this.settings.retryTimeout === null) {
|
|
131
169
|
return;
|
|
132
170
|
}
|
|
133
171
|
const oldAsyncFn = this.asyncFn;
|
|
134
|
-
const newAsyncFn = () => {
|
|
135
|
-
|
|
136
|
-
|
|
172
|
+
const newAsyncFn = async () => {
|
|
173
|
+
try {
|
|
174
|
+
if (this.settings.retryTimeout === null) {
|
|
175
|
+
throw new Error(`LazyPromise["time"] field is null`);
|
|
176
|
+
}
|
|
177
|
+
return await timeoutAndFail(oldAsyncFn, this.settings.retryTimeout);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof TimeoutAsyncError) {
|
|
181
|
+
this.eventBus.dispatch(new RetryTimeoutAsyncEvent({ error }));
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
137
184
|
}
|
|
138
|
-
return timeoutAndFail(oldAsyncFn, this.settings.retryTimeout);
|
|
139
185
|
};
|
|
140
186
|
this.asyncFn = newAsyncFn;
|
|
141
187
|
}
|
|
@@ -145,15 +191,34 @@ export class LazyPromise {
|
|
|
145
191
|
}
|
|
146
192
|
this.applyRetryTimeout();
|
|
147
193
|
const oldAsyncFn = this.asyncFn;
|
|
148
|
-
const newAsyncFn = () => {
|
|
149
|
-
|
|
150
|
-
|
|
194
|
+
const newAsyncFn = async () => {
|
|
195
|
+
try {
|
|
196
|
+
if (this.settings.retryAttempts === null) {
|
|
197
|
+
throw new Error(`LazyPromise["attempts"] field is null`);
|
|
198
|
+
}
|
|
199
|
+
return await retryOrFail(async (attempt) => {
|
|
200
|
+
try {
|
|
201
|
+
return await oldAsyncFn();
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
this.eventBus.dispatch(new RetryAttemptAsyncEvent({
|
|
205
|
+
attempt,
|
|
206
|
+
error,
|
|
207
|
+
}));
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}, {
|
|
211
|
+
backoffPolicy: this.settings.backoffPolicy ?? undefined,
|
|
212
|
+
retryPolicy: this.settings.retryPolicy ?? undefined,
|
|
213
|
+
maxAttempts: this.settings.retryAttempts,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
if (error instanceof RetryAsyncError) {
|
|
218
|
+
this.eventBus.dispatch(new RetryFailureAsyncEvent({ error }));
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
151
221
|
}
|
|
152
|
-
return retryOrFail(oldAsyncFn, {
|
|
153
|
-
backoffPolicy: this.settings.backoffPolicy ?? undefined,
|
|
154
|
-
retryPolicy: this.settings.retryPolicy ?? undefined,
|
|
155
|
-
maxAttempts: this.settings.retryAttempts,
|
|
156
|
-
});
|
|
157
222
|
};
|
|
158
223
|
this.asyncFn = newAsyncFn;
|
|
159
224
|
}
|
|
@@ -163,10 +228,18 @@ export class LazyPromise {
|
|
|
163
228
|
}
|
|
164
229
|
const oldAsyncFn = this.asyncFn;
|
|
165
230
|
const newAsyncFn = () => {
|
|
166
|
-
|
|
167
|
-
|
|
231
|
+
try {
|
|
232
|
+
if (this.settings.totalTimeout === null) {
|
|
233
|
+
throw new Error(`LazyPromise["time"] field is null`);
|
|
234
|
+
}
|
|
235
|
+
return timeoutAndFail(oldAsyncFn, this.settings.totalTimeout);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
if (error instanceof TimeoutAsyncError) {
|
|
239
|
+
this.eventBus.dispatch(new TotalTimeoutFailureAsyncEvent({ error }));
|
|
240
|
+
}
|
|
241
|
+
throw error;
|
|
168
242
|
}
|
|
169
|
-
return timeoutAndFail(oldAsyncFn, this.settings.totalTimeout);
|
|
170
243
|
};
|
|
171
244
|
this.asyncFn = newAsyncFn;
|
|
172
245
|
}
|
|
@@ -175,11 +248,19 @@ export class LazyPromise {
|
|
|
175
248
|
return;
|
|
176
249
|
}
|
|
177
250
|
const oldAsyncFn = this.asyncFn;
|
|
178
|
-
const newAsyncFn = () => {
|
|
179
|
-
|
|
180
|
-
|
|
251
|
+
const newAsyncFn = async () => {
|
|
252
|
+
try {
|
|
253
|
+
if (this.settings.abortSignal === null) {
|
|
254
|
+
throw new Error(`LazyPromise["abortSignal"] field is null`);
|
|
255
|
+
}
|
|
256
|
+
return await abortAndFail(oldAsyncFn, this.settings.abortSignal);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
if (error instanceof AbortAsyncError) {
|
|
260
|
+
this.eventBus.dispatch(new AbortAsyncEvent({ error }));
|
|
261
|
+
}
|
|
262
|
+
throw error;
|
|
181
263
|
}
|
|
182
|
-
return abortAndFail(oldAsyncFn, this.settings.abortSignal);
|
|
183
264
|
};
|
|
184
265
|
this.asyncFn = newAsyncFn;
|
|
185
266
|
}
|
|
@@ -188,21 +269,6 @@ export class LazyPromise {
|
|
|
188
269
|
this.applyTotalTimeout();
|
|
189
270
|
this.applyAbort();
|
|
190
271
|
}
|
|
191
|
-
/**
|
|
192
|
-
* @throws {AbortAsyncError} {@link AbortAsyncError}
|
|
193
|
-
* @throws {TimeoutAsyncError} {@link TimeoutAsyncError}
|
|
194
|
-
* @throws {RetryAsyncError} {@link RetryAsyncError}
|
|
195
|
-
*/
|
|
196
|
-
then(onfulfilled,
|
|
197
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
-
onrejected) {
|
|
199
|
-
this.applySettings();
|
|
200
|
-
if (this.promise === null) {
|
|
201
|
-
this.promise = this.asyncFn();
|
|
202
|
-
}
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
|
|
204
|
-
return this.promise.then(onfulfilled, onrejected);
|
|
205
|
-
}
|
|
206
272
|
/**
|
|
207
273
|
* The <i>setBackoffPolicy</i> method is used for setting a custom <i>{@link BackoffPolicy}</i>.
|
|
208
274
|
* ```ts
|
|
@@ -351,29 +417,26 @@ export class LazyPromise {
|
|
|
351
417
|
abortSignal,
|
|
352
418
|
});
|
|
353
419
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
return
|
|
368
|
-
...this.settings,
|
|
369
|
-
onError: cb,
|
|
370
|
-
});
|
|
420
|
+
/**
|
|
421
|
+
* @throws {AbortAsyncError} {@link AbortAsyncError}
|
|
422
|
+
* @throws {TimeoutAsyncError} {@link TimeoutAsyncError}
|
|
423
|
+
* @throws {RetryAsyncError} {@link RetryAsyncError}
|
|
424
|
+
*/
|
|
425
|
+
then(onfulfilled,
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
427
|
+
onrejected) {
|
|
428
|
+
this.applySettings();
|
|
429
|
+
if (this.promise === null) {
|
|
430
|
+
this.promise = this.asyncFn();
|
|
431
|
+
}
|
|
432
|
+
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
|
|
433
|
+
return this.promise.then(onfulfilled, onrejected);
|
|
371
434
|
}
|
|
372
435
|
/**
|
|
373
436
|
* The <i>defer</i> method executes the <i>LazyPromise</i> without awaiting it.
|
|
374
437
|
* @example
|
|
375
438
|
* ```ts
|
|
376
|
-
* import { LazyPromise } from "@daiso-tech/core";
|
|
439
|
+
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
377
440
|
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
378
441
|
*
|
|
379
442
|
* const promise =
|
|
@@ -391,25 +454,21 @@ export class LazyPromise {
|
|
|
391
454
|
* ```
|
|
392
455
|
*/
|
|
393
456
|
defer() {
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return value;
|
|
398
|
-
}
|
|
399
|
-
finally {
|
|
400
|
-
await this.settings.onFinally();
|
|
401
|
-
}
|
|
457
|
+
const onFinally = () => {
|
|
458
|
+
this.eventBus.dispatch(new FinallyAsyncEvent({}));
|
|
459
|
+
this.eventBus.clear();
|
|
402
460
|
};
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
461
|
+
const onSuccess = (value) => {
|
|
462
|
+
this.eventBus.dispatch(new SuccessAsyncEvent({ value }));
|
|
463
|
+
onFinally();
|
|
464
|
+
return value;
|
|
465
|
+
};
|
|
466
|
+
const onFailure = (error) => {
|
|
467
|
+
this.eventBus.dispatch(new FailureAsyncEvent({ error }));
|
|
468
|
+
onFinally();
|
|
469
|
+
return error;
|
|
411
470
|
};
|
|
412
|
-
this.then(
|
|
471
|
+
this.then(onSuccess, onFailure);
|
|
413
472
|
}
|
|
414
473
|
}
|
|
415
474
|
//# sourceMappingURL=lazy-promise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-promise.js","sourceRoot":"","sources":["../../../../src/async/utilities/lazy-promise/lazy-promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lazy-promise.js","sourceRoot":"","sources":["../../../../src/async/utilities/lazy-promise/lazy-promise.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO;AACH,6DAA6D;AAC7D,iBAAiB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO;AACH,6DAA6D;AAC7D,eAAe,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO;AACH,6DAA6D;AAC7D,eAAe,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,yBAAyB,EACzB,oBAAoB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AAC;IAED;;;;OAIG;IACH,IAAI,CACA,WAEU;IACV,8DAA8D;IAC9D,UAAuE;QAEvE,IAAI,CAAC,aAAa,EAAE,CAAC;QAErB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAClC,CAAC;QACD,qFAAqF;QACrF,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK;QACD,MAAM,SAAS,GAAG,GAAG,EAAE;YACnB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC,CAAC;QACF,MAAM,SAAS,GAAG,CAAC,KAAa,EAAU,EAAE;YACxC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACzD,SAAS,EAAE,CAAC;YACZ,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;QACF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE;YAC1C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACzD,SAAS,EAAE,CAAC;YACZ,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -26,4 +26,4 @@ export type RetrySettings = {
|
|
|
26
26
|
/**
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
|
-
export declare function retryOrFail<TValue = void>(asyncFn: () => PromiseLike<TValue>, settings?: RetrySettings): Promise<TValue>;
|
|
29
|
+
export declare function retryOrFail<TValue = void>(asyncFn: (attempt: number) => PromiseLike<TValue>, settings?: RetrySettings): Promise<TValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-or-fail.js","sourceRoot":"","sources":["../../../../src/async/utilities/retry/retry-or-fail.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAyB1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC7B,
|
|
1
|
+
{"version":3,"file":"retry-or-fail.js","sourceRoot":"","sources":["../../../../src/async/utilities/retry/retry-or-fail.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAyB1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC7B,OAAiD,EACjD,WAA0B,EAAE;IAE5B,MAAM,EACF,WAAW,GAAG,CAAC,EACf,aAAa,GAAG,wBAAwB,EAAE,EAC1C,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,GAC3B,GAAG,QAAQ,CAAC;IACb,IAAI,MAAe,CAAC;IACpB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;QACtD,IAAI,CAAC;YACD,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,MAAM,GAAG,KAAK,CAAC;YACf,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;gBACnC,MAAM,KAAK,CAAC;YAChB,CAAC;YACD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtB,MAAM,KAAK,CAAC;YAChB,CAAC;YACD,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3C,MAAM,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;IAED,IAAI,YAAY,GAAG,oCAAoC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC;IACnF,IAAI,MAAM,EAAE,CAAC;QACT,YAAY,GAAG,GAAG,YAAY,+BAA+B,MAAM,CAAC,MAAiB,CAAC,GAAG,CAAC;IAC9F,CAAC;IACD,MAAM,IAAI,eAAe,CAAC,YAAY,EAAE;QACpC,KAAK,EAAE,MAAM;QACb,WAAW;KACd,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -7,4 +7,4 @@ import type { RetrySettings } from "../../../async/utilities/retry/retry-or-fail
|
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export declare function retry<TValue = void>(asyncFn: () => PromiseLike<TValue>, settings?: RetrySettings): Promise<Result<TValue, RetryAsyncError>>;
|
|
10
|
+
export declare function retry<TValue = void>(asyncFn: (attempt: number) => PromiseLike<TValue>, settings?: RetrySettings): Promise<Result<TValue, RetryAsyncError>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../../src/async/utilities/retry/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACvB,
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../../src/async/utilities/retry/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACvB,OAAiD,EACjD,WAA0B,EAAE;IAE5B,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACnD,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACtB,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;QACD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -70,7 +70,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
70
70
|
* If it's an <i>Iterable</i>, it will be joined into a single string.
|
|
71
71
|
* Think of an <i>Iterable</i> as representing a path.
|
|
72
72
|
*
|
|
73
|
-
* @param defaultValue - can be
|
|
73
|
+
* @param defaultValue - can be regular value, sync or async <i>{@link Invokable}</i> value and <i>{@link LazyPromise}</i> value.
|
|
74
74
|
*/
|
|
75
75
|
getOr(key: OneOrMore<string>, defaultValue: AsyncLazyable<NoneFunc<TType>>): LazyPromise<TType>;
|
|
76
76
|
/**
|
|
@@ -80,7 +80,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
80
80
|
* If it's an <i>Iterable</i>, it will be joined into a single string.
|
|
81
81
|
* Think of an <i>Iterable</i> as representing a path.
|
|
82
82
|
*
|
|
83
|
-
* @param valueToAdd - can be
|
|
83
|
+
* @param valueToAdd - can be regular value, sync or async <i>{@link Invokable}</i> value and <i>{@link LazyPromise}</i> value.
|
|
84
84
|
*/
|
|
85
85
|
getOrAdd(key: OneOrMore<string>, valueToAdd: AsyncLazyable<NoneFunc<TType>>, ttl?: TimeSpan | null): LazyPromise<TType>;
|
|
86
86
|
/**
|