@daiso-tech/core 0.34.0 → 0.35.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 (149) hide show
  1. package/README.md +2 -4
  2. package/dist/async/_module-exports.d.ts +0 -1
  3. package/dist/async/_module-exports.js +0 -1
  4. package/dist/async/_module-exports.js.map +1 -1
  5. package/dist/async/async.errors.d.ts +19 -12
  6. package/dist/async/async.errors.js +27 -16
  7. package/dist/async/async.errors.js.map +1 -1
  8. package/dist/async/middlewares/_module.d.ts +3 -0
  9. package/dist/async/middlewares/_module.js +3 -0
  10. package/dist/async/middlewares/_module.js.map +1 -1
  11. package/dist/async/middlewares/_shared.d.ts +10 -0
  12. package/dist/async/middlewares/_shared.js +5 -0
  13. package/dist/async/middlewares/_shared.js.map +1 -0
  14. package/dist/async/middlewares/bulkhead/_module.d.ts +1 -0
  15. package/dist/async/middlewares/bulkhead/_module.js +2 -0
  16. package/dist/async/middlewares/bulkhead/_module.js.map +1 -0
  17. package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +80 -0
  18. package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +46 -0
  19. package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +1 -0
  20. package/dist/async/middlewares/dynamic/dynamic.middleware.d.ts +2 -2
  21. package/dist/async/middlewares/dynamic/dynamic.middleware.js +5 -5
  22. package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +1 -1
  23. package/dist/async/middlewares/fallback/fallback.middleware.d.ts +10 -8
  24. package/dist/async/middlewares/fallback/fallback.middleware.js +1 -1
  25. package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -1
  26. package/dist/async/middlewares/hedging/_module.d.ts +2 -0
  27. package/dist/async/middlewares/hedging/_module.js +3 -0
  28. package/dist/async/middlewares/hedging/_module.js.map +1 -0
  29. package/dist/async/middlewares/hedging/_shared.d.ts +93 -0
  30. package/dist/async/middlewares/hedging/_shared.js +5 -0
  31. package/dist/async/middlewares/hedging/_shared.js.map +1 -0
  32. package/dist/async/middlewares/hedging/concurrent-hedging/_module.d.ts +1 -0
  33. package/dist/async/middlewares/hedging/concurrent-hedging/_module.js +2 -0
  34. package/dist/async/middlewares/hedging/concurrent-hedging/_module.js.map +1 -0
  35. package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts +51 -0
  36. package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +138 -0
  37. package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +1 -0
  38. package/dist/async/middlewares/hedging/sequential-hedging/_module.d.ts +1 -0
  39. package/dist/async/middlewares/hedging/sequential-hedging/_module.js +2 -0
  40. package/dist/async/middlewares/hedging/sequential-hedging/_module.js.map +1 -0
  41. package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.d.ts +51 -0
  42. package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +104 -0
  43. package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +1 -0
  44. package/dist/async/middlewares/observe/observe.middleware.d.ts +14 -16
  45. package/dist/async/middlewares/observe/observe.middleware.js +1 -1
  46. package/dist/async/middlewares/observe/observe.middleware.js.map +1 -1
  47. package/dist/async/middlewares/retry/retry.middleware.d.ts +41 -36
  48. package/dist/async/middlewares/retry/retry.middleware.js +31 -28
  49. package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
  50. package/dist/async/middlewares/timeout/timeout.middleware.d.ts +34 -39
  51. package/dist/async/middlewares/timeout/timeout.middleware.js +30 -47
  52. package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -1
  53. package/dist/async/utilities/_module.d.ts +2 -0
  54. package/dist/async/utilities/_module.js +2 -0
  55. package/dist/async/utilities/_module.js.map +1 -1
  56. package/dist/async/utilities/abort-and-fail/abort-and-fail.d.ts +3 -0
  57. package/dist/async/utilities/abort-and-fail/abort-and-fail.js +6 -7
  58. package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +1 -1
  59. package/dist/async/utilities/lazy-promise/lazy-promise.js +0 -1
  60. package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
  61. package/dist/async/utilities/promise-queue/_module.d.ts +1 -0
  62. package/dist/async/utilities/promise-queue/_module.js +2 -0
  63. package/dist/async/utilities/promise-queue/_module.js.map +1 -0
  64. package/dist/async/utilities/promise-queue/promise-queue.d.ts +32 -0
  65. package/dist/async/utilities/promise-queue/promise-queue.js +107 -0
  66. package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -0
  67. package/dist/async/utilities/timeout-and-fail/_module.d.ts +1 -0
  68. package/dist/async/utilities/timeout-and-fail/_module.js +2 -0
  69. package/dist/async/utilities/timeout-and-fail/_module.js.map +1 -0
  70. package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
  71. package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +19 -0
  72. package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
  73. package/dist/cache/contracts/cache.contract.d.ts +2 -2
  74. package/dist/cache/contracts/cache.events.d.ts +43 -47
  75. package/dist/cache/contracts/cache.events.js +5 -103
  76. package/dist/cache/contracts/cache.events.js.map +1 -1
  77. package/dist/cache/implementations/derivables/cache/cache.d.ts +15 -15
  78. package/dist/cache/implementations/derivables/cache/cache.js +94 -79
  79. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  80. package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +1 -1
  81. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
  82. package/dist/cache/implementations/test-utilities/cache.test-suite.js +138 -147
  83. package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
  84. package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
  85. package/dist/event-bus/contracts/_module-exports.js +0 -1
  86. package/dist/event-bus/contracts/_module-exports.js.map +1 -1
  87. package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +6 -1
  88. package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +2 -3
  89. package/dist/event-bus/contracts/event-bus-factory.contract.js.map +1 -1
  90. package/dist/event-bus/contracts/event-bus.contract.d.ts +12 -23
  91. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +10 -10
  92. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +30 -30
  93. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  94. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +13 -7
  95. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +11 -5
  96. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
  97. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +0 -2
  98. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +13 -20
  99. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
  100. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +0 -2
  101. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +187 -207
  102. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
  103. package/dist/lock/contracts/lock-provider.contract.d.ts +2 -2
  104. package/dist/lock/contracts/lock.events.d.ts +35 -44
  105. package/dist/lock/contracts/lock.events.js +8 -90
  106. package/dist/lock/contracts/lock.events.js.map +1 -1
  107. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +9 -9
  108. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +12 -12
  109. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  110. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
  111. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
  112. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +2 -2
  113. package/dist/lock/implementations/derivables/lock-provider/lock.js +69 -50
  114. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  115. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +1 -1
  116. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  117. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +212 -212
  118. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
  119. package/dist/serde/contracts/flexible-serde.contract.d.ts +0 -11
  120. package/dist/serde/implementations/derivables/serde.d.ts +1 -32
  121. package/dist/serde/implementations/derivables/serde.js +0 -45
  122. package/dist/serde/implementations/derivables/serde.js.map +1 -1
  123. package/dist/utilities/classes/hooks/async-hooks.d.ts +107 -20
  124. package/dist/utilities/classes/hooks/async-hooks.js +47 -18
  125. package/dist/utilities/classes/hooks/async-hooks.js.map +1 -1
  126. package/dist/utilities/classes/hooks/hooks.d.ts +39 -21
  127. package/dist/utilities/classes/hooks/hooks.js +19 -18
  128. package/dist/utilities/classes/hooks/hooks.js.map +1 -1
  129. package/dist/utilities/classes/key-prefixer/key-prefixer.js +2 -2
  130. package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
  131. package/dist/utilities/contracts/_module.d.ts +0 -1
  132. package/dist/utilities/contracts/_module.js +0 -1
  133. package/dist/utilities/contracts/_module.js.map +1 -1
  134. package/dist/utilities/functions/invokable.d.ts +9 -5
  135. package/dist/utilities/functions/invokable.js +10 -0
  136. package/dist/utilities/functions/invokable.js.map +1 -1
  137. package/package.json +22 -2
  138. package/dist/async/async.events.d.ts +0 -105
  139. package/dist/async/async.events.js +0 -82
  140. package/dist/async/async.events.js.map +0 -1
  141. package/dist/event-bus/contracts/_shared.d.ts +0 -12
  142. package/dist/event-bus/contracts/_shared.js +0 -15
  143. package/dist/event-bus/contracts/_shared.js.map +0 -1
  144. package/dist/test.d.ts +0 -1
  145. package/dist/test.js +0 -34
  146. package/dist/test.js.map +0 -1
  147. package/dist/utilities/contracts/sync-event-bus-listenable.d.ts +0 -13
  148. package/dist/utilities/contracts/sync-event-bus-listenable.js +0 -5
  149. package/dist/utilities/contracts/sync-event-bus-listenable.js.map +0 -1
package/README.md CHANGED
@@ -28,6 +28,8 @@ A modular, framework-agnostic library providing essential components for modern
28
28
  - `exponentialBackoffPolicy`
29
29
  - `linearBackoffPolicy`
30
30
  - `polynomialBackoffPolicy`
31
+ - `sequentialHedging`: Runs fallbacks sequentially if the primary function fails, ensuring graceful failure handling.
32
+ - `concurrentHedging`: Executes the primary function alongside fallbacks concurrently, returning the first successful result and aborting all remaining operations.
31
33
  - `timeout`: Guaranteed execution time limits
32
34
  - **LazyPromise**:
33
35
  - Executes only when awaited
@@ -46,10 +48,6 @@ A modular, framework-agnostic library providing essential components for modern
46
48
  - SharedLock (ReaderWriterLock)
47
49
  - RateLimiter
48
50
  - CircuitBreaker
49
- - Heding middleware with multiple strategies:
50
- - fallback strategy
51
- - parallel strategy
52
- - latency strategy
53
51
  - MessageQueue
54
52
  - TaskScheduler
55
53
  - Notification system
@@ -2,4 +2,3 @@ export * from "../async/backof-policies/_module.js";
2
2
  export * from "../async/middlewares/_module.js";
3
3
  export * from "../async/utilities/_module.js";
4
4
  export * from "../async/async.errors.js";
5
- export * from "../async/async.events.js";
@@ -2,5 +2,4 @@ export * from "../async/backof-policies/_module.js";
2
2
  export * from "../async/middlewares/_module.js";
3
3
  export * from "../async/utilities/_module.js";
4
4
  export * from "../async/async.errors.js";
5
- export * from "../async/async.events.js";
6
5
  //# sourceMappingURL=_module-exports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../src/async/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../src/async/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC"}
@@ -10,16 +10,6 @@ export declare class AsyncError extends Error {
10
10
  constructor(message: string, cause?: unknown);
11
11
  }
12
12
  /**
13
- * This error is thrown when the is aborted.
14
- *
15
- * IMPORT_PATH: `"@daiso-tech/core/async"`
16
- * @group Errors
17
- */
18
- export declare class AbortAsyncError extends AsyncError {
19
- constructor(message: string, cause?: unknown);
20
- }
21
- /**
22
- * This error is thrown when the has exceeded the given time limit.
23
13
  *
24
14
  * IMPORT_PATH: `"@daiso-tech/core/async"`
25
15
  * @group Errors
@@ -37,7 +27,6 @@ export type RetryAsyncErrorData = {
37
27
  maxAttempts: number;
38
28
  };
39
29
  /**
40
- * This error is thrown when the has failed all retry attempts.
41
30
  *
42
31
  * IMPORT_PATH: `"@daiso-tech/core/async"`
43
32
  * @group Errors
@@ -47,6 +36,23 @@ export declare class RetryAsyncError extends AsyncError {
47
36
  readonly errors: unknown[];
48
37
  constructor(message: string, { errors, maxAttempts }: RetryAsyncErrorData);
49
38
  }
39
+ /**
40
+ *
41
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
42
+ * @group Errors
43
+ */
44
+ export declare class HedgingAsyncError extends AsyncError {
45
+ readonly errors: unknown[];
46
+ constructor(message: string, errors: unknown[]);
47
+ }
48
+ /**
49
+ *
50
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
51
+ * @group Errors
52
+ */
53
+ export declare class CapacityFullAsyncError extends AsyncError {
54
+ constructor(message: string, cause?: unknown);
55
+ }
50
56
  /**
51
57
  *
52
58
  * IMPORT_PATH: `"@daiso-tech/core/async"`
@@ -54,7 +60,8 @@ export declare class RetryAsyncError extends AsyncError {
54
60
  */
55
61
  export declare const ASYNC_ERRORS: {
56
62
  readonly Base: typeof AsyncError;
57
- readonly Abort: typeof AbortAsyncError;
58
63
  readonly Timeout: typeof TimeoutAsyncError;
59
64
  readonly Retry: typeof RetryAsyncError;
65
+ readonly Hedging: typeof HedgingAsyncError;
66
+ readonly CapacityFull: typeof CapacityFullAsyncError;
60
67
  };
@@ -13,19 +13,6 @@ export class AsyncError extends Error {
13
13
  }
14
14
  }
15
15
  /**
16
- * This error is thrown when the is aborted.
17
- *
18
- * IMPORT_PATH: `"@daiso-tech/core/async"`
19
- * @group Errors
20
- */
21
- export class AbortAsyncError extends AsyncError {
22
- constructor(message, cause) {
23
- super(message, cause);
24
- this.name = AbortAsyncError.name;
25
- }
26
- }
27
- /**
28
- * This error is thrown when the has exceeded the given time limit.
29
16
  *
30
17
  * IMPORT_PATH: `"@daiso-tech/core/async"`
31
18
  * @group Errors
@@ -37,7 +24,6 @@ export class TimeoutAsyncError extends AsyncError {
37
24
  }
38
25
  }
39
26
  /**
40
- * This error is thrown when the has failed all retry attempts.
41
27
  *
42
28
  * IMPORT_PATH: `"@daiso-tech/core/async"`
43
29
  * @group Errors
@@ -46,12 +32,36 @@ export class RetryAsyncError extends AsyncError {
46
32
  maxAttempts;
47
33
  errors = [];
48
34
  constructor(message, { errors, maxAttempts }) {
49
- super(message, errors[errors.length - 1]);
35
+ super(message, errors);
50
36
  this.errors = errors;
51
37
  this.maxAttempts = maxAttempts;
52
38
  this.name = RetryAsyncError.name;
53
39
  }
54
40
  }
41
+ /**
42
+ *
43
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
44
+ * @group Errors
45
+ */
46
+ export class HedgingAsyncError extends AsyncError {
47
+ errors;
48
+ constructor(message, errors) {
49
+ super(message, errors);
50
+ this.errors = errors;
51
+ this.name = HedgingAsyncError.name;
52
+ }
53
+ }
54
+ /**
55
+ *
56
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
57
+ * @group Errors
58
+ */
59
+ export class CapacityFullAsyncError extends AsyncError {
60
+ constructor(message, cause) {
61
+ super(message, cause);
62
+ this.name = CapacityFullAsyncError.name;
63
+ }
64
+ }
55
65
  /**
56
66
  *
57
67
  * IMPORT_PATH: `"@daiso-tech/core/async"`
@@ -59,8 +69,9 @@ export class RetryAsyncError extends AsyncError {
59
69
  */
60
70
  export const ASYNC_ERRORS = {
61
71
  Base: AsyncError,
62
- Abort: AbortAsyncError,
63
72
  Timeout: TimeoutAsyncError,
64
73
  Retry: RetryAsyncError,
74
+ Hedging: HedgingAsyncError,
75
+ CapacityFull: CapacityFullAsyncError,
65
76
  };
66
77
  //# sourceMappingURL=async.errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"async.errors.js","sourceRoot":"","sources":["../../src/async/async.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC3C,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;IACrC,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC7C,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ;AAYD;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC3B,WAAW,CAAS;IAEpB,MAAM,GAAc,EAAE,CAAC;IAEvC,YAAY,OAAe,EAAE,EAAE,MAAM,EAAE,WAAW,EAAuB;QACrE,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;IACrC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,iBAAiB;IAC1B,KAAK,EAAE,eAAe;CAChB,CAAC"}
1
+ {"version":3,"file":"async.errors.js","sourceRoot":"","sources":["../../src/async/async.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC7C,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ;AAYD;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC3B,WAAW,CAAS;IAEpB,MAAM,GAAc,EAAE,CAAC;IAEvC,YAAY,OAAe,EAAE,EAAE,MAAM,EAAE,WAAW,EAAuB;QACrE,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;IACrC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAGzB;IAFpB,YACI,OAAe,EACC,MAAiB;QAEjC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAFP,WAAM,GAAN,MAAM,CAAW;QAGjC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IAClD,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAC5C,CAAC;CACJ;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,iBAAiB;IAC1B,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,iBAAiB;IAC1B,YAAY,EAAE,sBAAsB;CAC9B,CAAC"}
@@ -1,5 +1,8 @@
1
+ export * from "../../async/middlewares/bulkhead/_module.js";
1
2
  export * from "../../async/middlewares/dynamic/_module.js";
2
3
  export * from "../../async/middlewares/fallback/_module.js";
4
+ export * from "../../async/middlewares/hedging/_module.js";
3
5
  export * from "../../async/middlewares/observe/_module.js";
4
6
  export * from "../../async/middlewares/retry/_module.js";
5
7
  export * from "../../async/middlewares/timeout/_module.js";
8
+ export * from "../../async/middlewares/_shared.js";
@@ -1,6 +1,9 @@
1
+ export * from "../../async/middlewares/bulkhead/_module.js";
1
2
  export * from "../../async/middlewares/dynamic/_module.js";
2
3
  export * from "../../async/middlewares/fallback/_module.js";
4
+ export * from "../../async/middlewares/hedging/_module.js";
3
5
  export * from "../../async/middlewares/observe/_module.js";
4
6
  export * from "../../async/middlewares/retry/_module.js";
5
7
  export * from "../../async/middlewares/timeout/_module.js";
8
+ export * from "../../async/middlewares/_shared.js";
6
9
  //# sourceMappingURL=_module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/async/middlewares/_module.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,wCAAwC,CAAC"}
1
+ {"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/async/middlewares/_module.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,wCAAwC,CAAC;AACvD,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module Async
3
+ */
4
+ import { type Invokable } from "../../utilities/_module-exports.js";
5
+ /**
6
+ *
7
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
8
+ * @group Middleware
9
+ */
10
+ export type ErrorPolicy = Invokable<[error: unknown], boolean>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @module Async
3
+ */
4
+ import {} from "../../utilities/_module-exports.js";
5
+ //# sourceMappingURL=_shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../src/async/middlewares/_shared.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAkB,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "../../../async/middlewares/bulkhead/bulkhead.middleware.js";
@@ -0,0 +1,2 @@
1
+ export * from "../../../async/middlewares/bulkhead/bulkhead.middleware.js";
2
+ //# sourceMappingURL=_module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/bulkhead/_module.ts"],"names":[],"mappings":"AAAA,cAAc,qDAAqD,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @module Async
3
+ */
4
+ import { TimeSpan, type AsyncMiddlewareFn, type HookContext, type Invokable } from "../../../utilities/_module-exports.js";
5
+ /**
6
+ *
7
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
8
+ * @group Middleware
9
+ */
10
+ export type OnProcessingData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
11
+ args: TParameters;
12
+ context: TContext;
13
+ };
14
+ /**
15
+ *
16
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
17
+ * @group Middleware
18
+ */
19
+ export type OnProcessing<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnProcessingData<TParameters, TContext>]>;
20
+ /**
21
+ *
22
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
23
+ * @group Middleware
24
+ */
25
+ export type BulkheadCallbacks<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
26
+ onProcessing?: OnProcessing<TParameters, TContext>;
27
+ };
28
+ /**
29
+ *
30
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
31
+ * @group Middleware
32
+ */
33
+ export type BulkheadSettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = BulkheadCallbacks<TParameters, TContext> & {
34
+ /**
35
+ * The maximum number of promises allowed to run concurrently. If this limit is exceeded, additional promises will be queued until a slot becomes available.
36
+ *
37
+ * @default {25}
38
+ */
39
+ maxConcurrency?: number;
40
+ /**
41
+ * The maximum capacity of the promise queue. If null, the queue can grow indefinitely.
42
+ * If a number is provided and the queue exceeds this limit, an error will be thrown, and no further promises will be enqueued.
43
+ *
44
+ * @default {null}
45
+ */
46
+ maxCapacity?: number | null;
47
+ /**
48
+ * @default
49
+ * ```ts
50
+ * import { TimeSpan } from "@daiso-tech/core/utilities";
51
+ *
52
+ * TimeSpan.fromMilliseconds(0)
53
+ * ```
54
+ */
55
+ interval?: TimeSpan;
56
+ };
57
+ /**
58
+ * The `bulkhead` middlewares ensures that a given amount of {@link Promiselike | `PromiseLike`} objects run at the same time concurrently and the rest will be queued up.
59
+ * You can provide {@link BulkheadSettings | `settings.maxCapacity`}
60
+ *
61
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
62
+ * @group Middleware
63
+ * @throws {CapacityFullAsyncError} {@link CapacityFullAsyncError}
64
+ * ```ts
65
+ * import { bulkhead } from "@daiso-tech/core/async";
66
+ * import { AsyncHooks } from "@daiso-tech/core/utilities";
67
+ *
68
+ * const fetchData = new AsyncHooks(async (url: string): Promise<unknown> => {
69
+ * const response = await fetch(url);
70
+ * const json = await response.json();
71
+ * return json;
72
+ * }, [
73
+ * bulkhead()
74
+ * ]);
75
+ *
76
+ * // Will run only 25 promises concurrently by default.
77
+ * await Promise.all(Array(50).fill("").map(() => fetchData.invoke("URL")));
78
+ * ```
79
+ */
80
+ export declare function bulkhead<TParameters extends unknown[], TReturn, TContext extends HookContext>(settings?: BulkheadSettings<TParameters, TContext>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module Async
3
+ */
4
+ import { callInvokable, TimeSpan, } from "../../../utilities/_module-exports.js";
5
+ import { PromiseQueue } from "../../../async/utilities/_module.js";
6
+ /**
7
+ * The `bulkhead` middlewares ensures that a given amount of {@link Promiselike | `PromiseLike`} objects run at the same time concurrently and the rest will be queued up.
8
+ * You can provide {@link BulkheadSettings | `settings.maxCapacity`}
9
+ *
10
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
11
+ * @group Middleware
12
+ * @throws {CapacityFullAsyncError} {@link CapacityFullAsyncError}
13
+ * ```ts
14
+ * import { bulkhead } from "@daiso-tech/core/async";
15
+ * import { AsyncHooks } from "@daiso-tech/core/utilities";
16
+ *
17
+ * const fetchData = new AsyncHooks(async (url: string): Promise<unknown> => {
18
+ * const response = await fetch(url);
19
+ * const json = await response.json();
20
+ * return json;
21
+ * }, [
22
+ * bulkhead()
23
+ * ]);
24
+ *
25
+ * // Will run only 25 promises concurrently by default.
26
+ * await Promise.all(Array(50).fill("").map(() => fetchData.invoke("URL")));
27
+ * ```
28
+ */
29
+ export function bulkhead(settings = {}) {
30
+ const { maxConcurrency = 25, maxCapacity = null, interval = TimeSpan.fromMilliseconds(0), onProcessing = () => { }, } = settings;
31
+ const promiseQueue = new PromiseQueue({
32
+ maxCapacity,
33
+ maxConcurrency,
34
+ interval,
35
+ });
36
+ return async (args, next, { context, signal }) => {
37
+ return await promiseQueue.add(() => {
38
+ callInvokable(onProcessing, {
39
+ args,
40
+ context,
41
+ });
42
+ return next(...args);
43
+ }, signal);
44
+ };
45
+ }
46
+ //# sourceMappingURL=bulkhead.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bulkhead.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/bulkhead/bulkhead.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,aAAa,EACb,QAAQ,GAIX,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAwE5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,QAAQ,CAKpB,WAAoD,EAAE;IAEtD,MAAM,EACF,cAAc,GAAG,EAAE,EACnB,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,EACvC,YAAY,GAAG,GAAG,EAAE,GAAE,CAAC,GAC1B,GAAG,QAAQ,CAAC;IACb,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;QAClC,WAAW;QACX,cAAc;QACd,QAAQ;KACX,CAAC,CAAC;IACH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;QAC7C,OAAO,MAAM,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE;YAC/B,aAAa,CAAC,YAAY,EAAE;gBACxB,IAAI;gBACJ,OAAO;aACV,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,EAAE,MAAM,CAAC,CAAC;IACf,CAAC,CAAC;AACN,CAAC"}
@@ -11,8 +11,8 @@ import { type AsyncMiddlewareFn, type Invokable } from "../../../utilities/_modu
11
11
  *
12
12
  * @example
13
13
  * ```ts
14
- * import { AsyncHooks } from "@daiso-tech/core/async";
15
- * import { dynamic, fallback } from "@daiso-tech/core/utilities";
14
+ * import { dynamic, fallback } from "@daiso-tech/core/async";
15
+ * import { AsyncHooks } from "@daiso-tech/core/utilities";
16
16
  *
17
17
  * await new AsyncHooks(
18
18
  * (a: number, b: number) => a / b,
@@ -10,8 +10,8 @@ import { callInvokable, } from "../../../utilities/_module-exports.js";
10
10
  *
11
11
  * @example
12
12
  * ```ts
13
- * import { AsyncHooks } from "@daiso-tech/core/async";
14
- * import { dynamic, fallback } from "@daiso-tech/core/utilities";
13
+ * import { dynamic, fallback } from "@daiso-tech/core/async";
14
+ * import { AsyncHooks } from "@daiso-tech/core/utilities";
15
15
  *
16
16
  * await new AsyncHooks(
17
17
  * (a: number, b: number) => a / b,
@@ -28,9 +28,9 @@ import { callInvokable, } from "../../../utilities/_module-exports.js";
28
28
  * ```
29
29
  */
30
30
  export function dynamic(dynamic) {
31
- return (args, next, context) => {
32
- const middleware = callInvokable(dynamic, args, context);
33
- return callInvokable(middleware, args, next, context);
31
+ return (args, next, settings) => {
32
+ const middleware = callInvokable(dynamic, args, settings.context);
33
+ return callInvokable(middleware, args, next, settings);
34
34
  };
35
35
  }
36
36
  //# sourceMappingURL=dynamic.middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/dynamic/dynamic.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EACH,aAAa,GAGhB,MAAM,gCAAgC,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,OAAO,CAKnB,OAKC;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAC3B,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACzD,OAAO,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"dynamic.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/dynamic/dynamic.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EACH,aAAa,GAGhB,MAAM,gCAAgC,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,OAAO,CAKnB,OAKC;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;QAC5B,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClE,OAAO,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC3D,CAAC,CAAC;AACN,CAAC"}
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import type { HookContext, AsyncLazyable } from "../../../utilities/_module-exports.js";
5
5
  import { type AsyncMiddlewareFn, type Invokable } from "../../../utilities/_module-exports.js";
6
+ import type { ErrorPolicy } from "../../../async/middlewares/_shared.js";
6
7
  /**
7
8
  *
8
9
  * IMPORT_PATH: `"@daiso-tech/core/async"`
@@ -25,27 +26,28 @@ export type OnFallback<TParameters extends unknown[] = unknown[], TFallbackValue
25
26
  * IMPORT_PATH: `"@daiso-tech/core/async"`
26
27
  * @group Middleware
27
28
  */
28
- export type FallbackPolicy = Invokable<[error: unknown], boolean>;
29
+ export type FallbackCallbacks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = {
30
+ /**
31
+ * Callback function that will be called before fallback values is returned.
32
+ */
33
+ onFallback?: OnFallback<TParameters, TReturn, TContext>;
34
+ };
29
35
  /**
30
36
  *
31
37
  * IMPORT_PATH: `"@daiso-tech/core/async"`
32
38
  * @group Middleware
33
39
  */
34
- export type FallbackSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = {
40
+ export type FallbackSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = FallbackCallbacks<TParameters, TReturn, TContext> & {
35
41
  fallbackValue: AsyncLazyable<TReturn>;
36
42
  /**
37
43
  * You can choose what errors you want to add fallback value. By default fallback value will be added to all errors.
38
44
  *
39
45
  * @default
40
46
  * ```ts
41
- * () => true
47
+ * (_error: unknown) => true
42
48
  * ```
43
49
  */
44
- fallbackPolicy?: FallbackPolicy;
45
- /**
46
- * Callback function that will be called before fallback values is returned.
47
- */
48
- onFallback?: OnFallback<TParameters, TReturn, TContext>;
50
+ fallbackPolicy?: ErrorPolicy;
49
51
  };
50
52
  /**
51
53
  * The `fallback` middleware adds fallback value when an error occurs.
@@ -30,7 +30,7 @@ import { callInvokable, resolveAsyncLazyable, } from "../../../utilities/_module
30
30
  */
31
31
  export function fallback(settings) {
32
32
  const { fallbackValue, fallbackPolicy = () => true, onFallback = () => { }, } = settings;
33
- return async (args, next, context) => {
33
+ return async (args, next, { context }) => {
34
34
  try {
35
35
  return await next(...args);
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fallback.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/fallback.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EACH,aAAa,EACb,oBAAoB,GAGvB,MAAM,gCAAgC,CAAC;AAgExC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,QAAQ,CAKpB,QAAmE;IAEnE,MAAM,EACF,aAAa,EACb,cAAc,GAAG,GAAG,EAAE,CAAC,IAAI,EAC3B,UAAU,GAAG,GAAG,EAAE,GAAE,CAAC,GACxB,GAAG,QAAQ,CAAC;IACb,OAAO,KAAK,EACR,IAAiB,EACjB,IAAyC,EACzC,OAAiB,EACD,EAAE;QAClB,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,IAAI,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;gBACvC,MAAM,qBAAqB,GACvB,MAAM,oBAAoB,CAAC,aAAa,CAAC,CAAC;gBAC9C,aAAa,CAAC,UAAU,EAAE;oBACtB,KAAK;oBACL,aAAa,EAAE,qBAAqB;oBACpC,IAAI;oBACJ,OAAO;iBACV,CAAC,CAAC;gBACH,OAAO,qBAAqB,CAAC;YACjC,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"fallback.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/fallback.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EACH,aAAa,EACb,oBAAoB,GAGvB,MAAM,gCAAgC,CAAC;AAqExC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,QAAQ,CAKpB,QAAmE;IAEnE,MAAM,EACF,aAAa,EACb,cAAc,GAAG,GAAG,EAAE,CAAC,IAAI,EAC3B,UAAU,GAAG,GAAG,EAAE,GAAE,CAAC,GACxB,GAAG,QAAQ,CAAC;IACb,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAoB,EAAE;QACvD,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,IAAI,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;gBACvC,MAAM,qBAAqB,GACvB,MAAM,oBAAoB,CAAC,aAAa,CAAC,CAAC;gBAC9C,aAAa,CAAC,UAAU,EAAE;oBACtB,KAAK;oBACL,aAAa,EAAE,qBAAqB;oBACpC,IAAI;oBACJ,OAAO;iBACV,CAAC,CAAC;gBACH,OAAO,qBAAqB,CAAC;YACjC,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "../../../async/middlewares/hedging/concurrent-hedging/_module.js";
2
+ export * from "../../../async/middlewares/hedging/sequential-hedging/_module.js";
@@ -0,0 +1,3 @@
1
+ export * from "../../../async/middlewares/hedging/concurrent-hedging/_module.js";
2
+ export * from "../../../async/middlewares/hedging/sequential-hedging/_module.js";
3
+ //# sourceMappingURL=_module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/_module.ts"],"names":[],"mappings":"AAAA,cAAc,2DAA2D,CAAC;AAC1E,cAAc,2DAA2D,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @module Async
3
+ */
4
+ import type { TimeSpan } from "../../../utilities/_module-exports.js";
5
+ import { type HookContext, type Invokable, type OneOrMore, type Promisable } from "../../../utilities/_module-exports.js";
6
+ /**
7
+ *
8
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
9
+ * @group Middlewares
10
+ */
11
+ export type OnHedgeAttemptData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
12
+ name: string;
13
+ args: TParameters;
14
+ context: TContext;
15
+ };
16
+ /**
17
+ *
18
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
19
+ * @group Middlewares
20
+ */
21
+ export type OnHedgeAttempt<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnHedgeAttemptData<TParameters, TContext>]>;
22
+ /**
23
+ *
24
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
25
+ * @group Middlewares
26
+ */
27
+ export type OnHedgeErrorData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
28
+ name: string;
29
+ error: unknown;
30
+ args: TParameters;
31
+ context: TContext;
32
+ };
33
+ /**
34
+ *
35
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
36
+ * @group Middlewares
37
+ */
38
+ export type OnHedgeError<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnHedgeErrorData<TParameters, TContext>]>;
39
+ /**
40
+ *
41
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
42
+ * @group Middlewares
43
+ */
44
+ export type HedgingCallbacks<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
45
+ /**
46
+ * Callback function that will be called before execution attempt.
47
+ */
48
+ onHedgeAttempt?: OnHedgeAttempt<TParameters, TContext>;
49
+ /**
50
+ * Callback function that will be called when the error occurs.
51
+ */
52
+ onHedgeError?: OnHedgeError<TParameters, TContext>;
53
+ };
54
+ /**
55
+ *
56
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
57
+ * @group Middlewares
58
+ */
59
+ export type Fallback<TParameters extends unknown[] = unknown[], TReturn = unknown> = Invokable<TParameters, Promisable<TReturn>>;
60
+ /**
61
+ *
62
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
63
+ * @group Middlewares
64
+ */
65
+ export type NamedFallback<TParameters extends unknown[] = unknown[], TReturn = unknown> = {
66
+ /**
67
+ * You can assign a custom name to the fallback function for easier identification in logs.
68
+ */
69
+ name: string;
70
+ func: Fallback<TParameters, TReturn>;
71
+ };
72
+ /**
73
+ *
74
+ * IMPORT_PATH: `"@daiso-tech/core/async"`
75
+ * @group Middlewares
76
+ */
77
+ export type HedgingSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = HedgingCallbacks<TParameters, TContext> & {
78
+ /**
79
+ * The maximum time to wait before automatically aborting the executing primary function or fallback functions.
80
+ *
81
+ * @default
82
+ * ```ts
83
+ * import { TimeSpan } from "@daiso-tech/core/utilities";
84
+ *
85
+ * TimeSpan.fromSeconds(2)
86
+ * ```
87
+ */
88
+ waitTime?: TimeSpan;
89
+ /**
90
+ * The fallback functions that run in case the primary function fails.
91
+ */
92
+ fallbacks: OneOrMore<Fallback<TParameters, TReturn> | NamedFallback<TParameters, TReturn>>;
93
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @module Async
3
+ */
4
+ import {} from "../../../utilities/_module-exports.js";
5
+ //# sourceMappingURL=_shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/_shared.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAKN,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "../../../../async/middlewares/hedging/concurrent-hedging/_module.js";
@@ -0,0 +1,2 @@
1
+ export * from "../../../../async/middlewares/hedging/concurrent-hedging/_module.js";
2
+ //# sourceMappingURL=_module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../../src/async/middlewares/hedging/concurrent-hedging/_module.ts"],"names":[],"mappings":"AAAA,cAAc,2DAA2D,CAAC"}