@jonloucks/concurrency-ts 0.4.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 (174) hide show
  1. package/README.md +248 -0
  2. package/api/Completable.d.ts +51 -0
  3. package/api/Completable.d.ts.map +1 -0
  4. package/api/Completable.js +11 -0
  5. package/api/Completable.js.map +1 -0
  6. package/api/CompletableFactory.d.ts +29 -0
  7. package/api/CompletableFactory.d.ts.map +1 -0
  8. package/api/CompletableFactory.js +19 -0
  9. package/api/CompletableFactory.js.map +1 -0
  10. package/api/Completion.d.ts +18 -0
  11. package/api/Completion.d.ts.map +1 -0
  12. package/api/Completion.js +2 -0
  13. package/api/Completion.js.map +1 -0
  14. package/api/CompletionNotify.d.ts +23 -0
  15. package/api/CompletionNotify.d.ts.map +1 -0
  16. package/api/CompletionNotify.js +11 -0
  17. package/api/CompletionNotify.js.map +1 -0
  18. package/api/CompletionState.d.ts +35 -0
  19. package/api/CompletionState.d.ts.map +1 -0
  20. package/api/CompletionState.js +64 -0
  21. package/api/CompletionState.js.map +1 -0
  22. package/api/Concurrency.d.ts +90 -0
  23. package/api/Concurrency.d.ts.map +1 -0
  24. package/api/Concurrency.js +19 -0
  25. package/api/Concurrency.js.map +1 -0
  26. package/api/ConcurrencyException.d.ts +27 -0
  27. package/api/ConcurrencyException.d.ts.map +1 -0
  28. package/api/ConcurrencyException.js +53 -0
  29. package/api/ConcurrencyException.js.map +1 -0
  30. package/api/ConcurrencyFactory.d.ts +41 -0
  31. package/api/ConcurrencyFactory.d.ts.map +1 -0
  32. package/api/ConcurrencyFactory.js +19 -0
  33. package/api/ConcurrencyFactory.js.map +1 -0
  34. package/api/IsCompleted.d.ts +20 -0
  35. package/api/IsCompleted.d.ts.map +1 -0
  36. package/api/IsCompleted.js +11 -0
  37. package/api/IsCompleted.js.map +1 -0
  38. package/api/OnCompletion.d.ts +23 -0
  39. package/api/OnCompletion.d.ts.map +1 -0
  40. package/api/OnCompletion.js +12 -0
  41. package/api/OnCompletion.js.map +1 -0
  42. package/api/Rule.d.ts +28 -0
  43. package/api/Rule.d.ts.map +1 -0
  44. package/api/Rule.js +11 -0
  45. package/api/Rule.js.map +1 -0
  46. package/api/StateMachine.d.ts +95 -0
  47. package/api/StateMachine.d.ts.map +1 -0
  48. package/api/StateMachine.js +13 -0
  49. package/api/StateMachine.js.map +1 -0
  50. package/api/StateMachineFactory.d.ts +29 -0
  51. package/api/StateMachineFactory.d.ts.map +1 -0
  52. package/api/StateMachineFactory.js +19 -0
  53. package/api/StateMachineFactory.js.map +1 -0
  54. package/api/TimeoutException.d.ts +21 -0
  55. package/api/TimeoutException.d.ts.map +1 -0
  56. package/api/TimeoutException.js +27 -0
  57. package/api/TimeoutException.js.map +1 -0
  58. package/api/Transition.d.ts +44 -0
  59. package/api/Transition.d.ts.map +1 -0
  60. package/api/Transition.js +11 -0
  61. package/api/Transition.js.map +1 -0
  62. package/api/Types.d.ts +27 -0
  63. package/api/Types.d.ts.map +1 -0
  64. package/api/Types.js +28 -0
  65. package/api/Types.js.map +1 -0
  66. package/api/Waitable.d.ts +39 -0
  67. package/api/Waitable.d.ts.map +1 -0
  68. package/api/Waitable.js +17 -0
  69. package/api/Waitable.js.map +1 -0
  70. package/api/WaitableConsumer.d.ts +54 -0
  71. package/api/WaitableConsumer.d.ts.map +1 -0
  72. package/api/WaitableConsumer.js +11 -0
  73. package/api/WaitableConsumer.js.map +1 -0
  74. package/api/WaitableFactory.d.ts +29 -0
  75. package/api/WaitableFactory.d.ts.map +1 -0
  76. package/api/WaitableFactory.js +19 -0
  77. package/api/WaitableFactory.js.map +1 -0
  78. package/api/WaitableNotify.d.ts +31 -0
  79. package/api/WaitableNotify.d.ts.map +1 -0
  80. package/api/WaitableNotify.js +12 -0
  81. package/api/WaitableNotify.js.map +1 -0
  82. package/api/WaitableSupplier.d.ts +53 -0
  83. package/api/WaitableSupplier.d.ts.map +1 -0
  84. package/api/WaitableSupplier.js +11 -0
  85. package/api/WaitableSupplier.js.map +1 -0
  86. package/auxiliary/Checks.d.ts +116 -0
  87. package/auxiliary/Checks.d.ts.map +1 -0
  88. package/auxiliary/Checks.js +145 -0
  89. package/auxiliary/Checks.js.map +1 -0
  90. package/auxiliary/Consumer.d.ts +45 -0
  91. package/auxiliary/Consumer.d.ts.map +1 -0
  92. package/auxiliary/Consumer.js +45 -0
  93. package/auxiliary/Consumer.js.map +1 -0
  94. package/auxiliary/Predicate.d.ts +55 -0
  95. package/auxiliary/Predicate.d.ts.map +1 -0
  96. package/auxiliary/Predicate.js +73 -0
  97. package/auxiliary/Predicate.js.map +1 -0
  98. package/auxiliary/Supplier.d.ts +52 -0
  99. package/auxiliary/Supplier.d.ts.map +1 -0
  100. package/auxiliary/Supplier.js +67 -0
  101. package/auxiliary/Supplier.js.map +1 -0
  102. package/impl/Completable.impl.d.ts +10 -0
  103. package/impl/Completable.impl.d.ts.map +1 -0
  104. package/impl/Completable.impl.js +136 -0
  105. package/impl/Completable.impl.js.map +1 -0
  106. package/impl/CompletableFactory.impl.d.ts +9 -0
  107. package/impl/CompletableFactory.impl.d.ts.map +1 -0
  108. package/impl/CompletableFactory.impl.js +42 -0
  109. package/impl/CompletableFactory.impl.js.map +1 -0
  110. package/impl/CompleteLater.impl.d.ts +12 -0
  111. package/impl/CompleteLater.impl.d.ts.map +1 -0
  112. package/impl/CompleteLater.impl.js +31 -0
  113. package/impl/CompleteLater.impl.js.map +1 -0
  114. package/impl/CompleteNow.impl.d.ts +14 -0
  115. package/impl/CompleteNow.impl.d.ts.map +1 -0
  116. package/impl/CompleteNow.impl.js +33 -0
  117. package/impl/CompleteNow.impl.js.map +1 -0
  118. package/impl/Concurrency.impl.d.ts +9 -0
  119. package/impl/Concurrency.impl.d.ts.map +1 -0
  120. package/impl/Concurrency.impl.js +84 -0
  121. package/impl/Concurrency.impl.js.map +1 -0
  122. package/impl/ConcurrencyFactory.impl.d.ts +10 -0
  123. package/impl/ConcurrencyFactory.impl.d.ts.map +1 -0
  124. package/impl/ConcurrencyFactory.impl.js +74 -0
  125. package/impl/ConcurrencyFactory.impl.js.map +1 -0
  126. package/impl/ConcurrencyWrapper.impl.d.ts +13 -0
  127. package/impl/ConcurrencyWrapper.impl.d.ts.map +1 -0
  128. package/impl/ConcurrencyWrapper.impl.js +85 -0
  129. package/impl/ConcurrencyWrapper.impl.js.map +1 -0
  130. package/impl/Events.d.ts +25 -0
  131. package/impl/Events.d.ts.map +1 -0
  132. package/impl/Events.impl.d.ts +11 -0
  133. package/impl/Events.impl.d.ts.map +1 -0
  134. package/impl/Events.impl.js +63 -0
  135. package/impl/Events.impl.js.map +1 -0
  136. package/impl/Events.js +3 -0
  137. package/impl/Events.js.map +1 -0
  138. package/impl/ExposedPromise.d.ts +26 -0
  139. package/impl/ExposedPromise.d.ts.map +1 -0
  140. package/impl/ExposedPromise.impl.d.ts +9 -0
  141. package/impl/ExposedPromise.impl.d.ts.map +1 -0
  142. package/impl/ExposedPromise.impl.js +41 -0
  143. package/impl/ExposedPromise.impl.js.map +1 -0
  144. package/impl/ExposedPromise.js +2 -0
  145. package/impl/ExposedPromise.js.map +1 -0
  146. package/impl/Internal.impl.d.ts +35 -0
  147. package/impl/Internal.impl.d.ts.map +1 -0
  148. package/impl/Internal.impl.js +90 -0
  149. package/impl/Internal.impl.js.map +1 -0
  150. package/impl/StateMachine.impl.d.ts +9 -0
  151. package/impl/StateMachine.impl.d.ts.map +1 -0
  152. package/impl/StateMachine.impl.js +184 -0
  153. package/impl/StateMachine.impl.js.map +1 -0
  154. package/impl/StateMachineFactory.impl.d.ts +9 -0
  155. package/impl/StateMachineFactory.impl.d.ts.map +1 -0
  156. package/impl/StateMachineFactory.impl.js +43 -0
  157. package/impl/StateMachineFactory.impl.js.map +1 -0
  158. package/impl/Waitable.impl.d.ts +8 -0
  159. package/impl/Waitable.impl.d.ts.map +1 -0
  160. package/impl/Waitable.impl.js +212 -0
  161. package/impl/Waitable.impl.js.map +1 -0
  162. package/impl/WaitableFactory.impl.d.ts +9 -0
  163. package/impl/WaitableFactory.impl.d.ts.map +1 -0
  164. package/impl/WaitableFactory.impl.js +42 -0
  165. package/impl/WaitableFactory.impl.js.map +1 -0
  166. package/index.d.ts +25 -0
  167. package/index.d.ts.map +1 -0
  168. package/index.js +33 -0
  169. package/index.js.map +1 -0
  170. package/package.json +88 -0
  171. package/version.d.ts +3 -0
  172. package/version.d.ts.map +1 -0
  173. package/version.js +4 -0
  174. package/version.js.map +1 -0
@@ -0,0 +1,145 @@
1
+ import { MAX_TIMEOUT } from "@jonloucks/concurrency-ts/api/Types";
2
+ import { illegalCheck, presentCheck, configCheck } from "@jonloucks/contracts-ts/auxiliary/Checks";
3
+ export { presentCheck, illegalCheck, configCheck };
4
+ /**
5
+ * Check that a state is present
6
+ *
7
+ * @param state the state to check
8
+ * @return the state if present
9
+ * @throws IllegalArgumentException if the state is not present
10
+ */
11
+ export function stateCheck(state) {
12
+ return presentCheck(state, "State must be present.");
13
+ }
14
+ /**
15
+ * Check that an event is present
16
+ *
17
+ * @param event the event to check
18
+ * @return the event if present
19
+ * @throws IllegalArgumentException if the event is not present
20
+ */
21
+ export function eventCheck(event) {
22
+ return presentCheck(event, "Event must be present.");
23
+ }
24
+ /**
25
+ * Check that a rule is present
26
+ *
27
+ * @param rule the rule to check
28
+ * @return the rule if present
29
+ * @throws IllegalArgumentException if the rule is not present
30
+ */
31
+ export function ruleCheck(rule) {
32
+ return presentCheck(rule, "Rule must be present.");
33
+ }
34
+ /**
35
+ * Check that rules are present
36
+ *
37
+ * @param rules the rules to check
38
+ * @return the rules if present
39
+ * @throws IllegalArgumentException if the rules are not present
40
+ */
41
+ export function rulesCheck(rules) {
42
+ return presentCheck(rules, "Rules must be present.");
43
+ }
44
+ /**
45
+ * Check that a listener is present
46
+ *
47
+ * @param consumer the listener to check
48
+ * @return the listener if present
49
+ * @throws IllegalArgumentException if the listener is not present
50
+ */
51
+ export function listenerCheck(consumer) {
52
+ return presentCheck(consumer, "Listener must be present.");
53
+ }
54
+ /**
55
+ * Check that a timeout is valid
56
+ *
57
+ * @param timeout the timeout to check
58
+ * @return the timeout if valid
59
+ * @throws IllegalArgumentException if the timeout is not valid
60
+ */
61
+ export function timeoutCheck(timeout) {
62
+ const presentTimeout = presentCheck(timeout, "Timeout must be present.");
63
+ illegalCheck(timeout, timeout.milliSeconds < 0, "Timeout must not be negative.");
64
+ illegalCheck(timeout, timeout.milliSeconds > MAX_TIMEOUT.milliSeconds, "Timeout must be less than or equal to maximum time.");
65
+ return presentTimeout;
66
+ }
67
+ /**
68
+ * Check that a completion value is present
69
+ *
70
+ * @param completion the completion value to check
71
+ * @return the completion value if present
72
+ * @throws IllegalArgumentException if the completion value is not present
73
+ */
74
+ export function completionCheck(completion) {
75
+ return presentCheck(completion, "Completion must be present.");
76
+ }
77
+ /**
78
+ * Check that an onCompletion consumer is present
79
+ *
80
+ * @param onCompletion the onCompletion consumer to check
81
+ * @return the onCompletion consumer if present
82
+ * @throws IllegalArgumentException if the onCompletion consumer is not present
83
+ */
84
+ export function onCompletionCheck(onCompletion) {
85
+ return presentCheck(onCompletion, "OnCompletion consumer must be present.");
86
+ }
87
+ /**
88
+ * Check that a finally block is present
89
+ *
90
+ * @param block the finally block to check
91
+ * @return the finally block if present
92
+ * @throws IllegalArgumentException if the finally block is not present
93
+ */
94
+ export function finallyBlockCheck(block) {
95
+ return presentCheck(block, "OnFinally consumer must be present.");
96
+ }
97
+ /**
98
+ * Check that a success block is present
99
+ *
100
+ * @param onSuccess the success block to check
101
+ * @return the success block if present
102
+ * @throws IllegalArgumentException if the success block is not present
103
+ */
104
+ export function successBlockCheck(onSuccess) {
105
+ return presentCheck(onSuccess, "OnSuccess consumer must be present.");
106
+ }
107
+ /**
108
+ * Check that a failure block is present
109
+ *
110
+ * @param onFailure the failure block to check
111
+ * @return the failure block if present
112
+ * @throws IllegalArgumentException if the failure block is not present
113
+ */
114
+ export function failureBlockCheck(onFailure) {
115
+ return presentCheck(onFailure, "OnFailure consumer must be present.");
116
+ }
117
+ /**
118
+ * Check that a predicate is present
119
+ *
120
+ * @param predicate the predicate to check
121
+ * @return the predicate if present
122
+ * @throws IllegalArgumentException if the predicate is not present
123
+ */
124
+ export function predicateCheck(predicate) {
125
+ return presentCheck(predicate, "Predicate must be present.");
126
+ }
127
+ /**
128
+ * Check that an initial value is present
129
+ *
130
+ * @param initialValue the initial value to check
131
+ * @return the initial value if present
132
+ * @throws IllegalArgumentException if the initial value is not present
133
+ */
134
+ export function initialValueCheck(initialValue) {
135
+ return presentCheck(initialValue, "Initial value must be present.");
136
+ }
137
+ /**
138
+ * explicitly mark a value as used to avoid compiler warnings
139
+ * useful for "using" variable which are used for disposal or other side-effects
140
+ * but not directly referenced in code.
141
+ *
142
+ * @param value the value which you wish to declare as used
143
+ */
144
+ export const used = (value) => { void value; };
145
+ //# sourceMappingURL=Checks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Checks.js","sourceRoot":"","sources":["../../src/auxiliary/Checks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAA8B,MAAM,qCAAqC,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAEnG,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAC,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAI,KAAQ;IACpC,OAAO,YAAY,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,YAAY,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAI,IAAO;IAClC,OAAO,YAAY,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAI,KAAmB;IAC/C,OAAO,YAAY,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAI,QAAW;IAC1C,OAAO,YAAY,CAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAiB;IAC5C,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;IACzE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;IACjF,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,GAAG,WAAW,CAAC,YAAY,EAAE,qDAAqD,CAAC,CAAC;IAC9H,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAI,UAA2B;IAC5D,OAAO,YAAY,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAI,YAA6B;IAChE,OAAO,YAAY,CAAC,YAAY,EAAE,wCAAwC,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAI,KAAsB;IACzD,OAAO,YAAY,CAAC,KAAK,EAAE,qCAAqC,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAI,SAA0B;IAC7D,OAAO,YAAY,CAAC,SAAS,EAAE,qCAAqC,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAI,SAA0B;IAC7D,OAAO,YAAY,CAAC,SAAS,EAAE,qCAAqC,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAI,SAA0B;IAC1D,OAAO,YAAY,CAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAI,YAA6B;IAChE,OAAO,YAAY,CAAC,YAAY,EAAE,gCAAgC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,IAAI,GAEb,CAAC,KAAc,EAAE,EAAE,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Consumer.ts
3
+ * Candidate for inclusion in api-ts
4
+ * Defines a Consumer type that can consume values of type T.
5
+ */
6
+ import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
7
+ /**
8
+ * A method that consumes a value of type T
9
+ */
10
+ export type Method<T> = (value: T) => void;
11
+ /**
12
+ * A Consumer that consumes values of type T
13
+ */
14
+ export interface Consumer<T> {
15
+ consume(value: T): void;
16
+ }
17
+ /**
18
+ * A type that can be either a Method or a Consumer
19
+ */
20
+ export type Type<T> = Method<T> | Consumer<T>;
21
+ /**
22
+ * Duck type guard check for Consumer
23
+ *
24
+ * @param instance the instance to check
25
+ * @param <T> the type of value consumed
26
+ * @returns true if instance is a Consumer, false otherwise
27
+ */
28
+ export declare function guard<T>(instance: unknown): instance is RequiredType<Consumer<T>>;
29
+ /**
30
+ * Convert a Type to a Consumer
31
+ *
32
+ * @param type the type to convert
33
+ * @param <T> the type of value consumed
34
+ * @returns a Consumer that consumes values of type T
35
+ */
36
+ export declare function fromType<T>(type: Type<T>): RequiredType<Consumer<T>>;
37
+ /**
38
+ * Check that a Consumer is present
39
+ *
40
+ * @param consumer the consumer to check
41
+ * @return the consumer if present
42
+ * @throws IllegalArgumentException if the consumer is not present
43
+ */
44
+ export declare function check<T>(consumer: Type<T>): Type<T>;
45
+ //# sourceMappingURL=Consumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Consumer.d.ts","sourceRoot":"","sources":["../../src/auxiliary/Consumer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAkB,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAGjF;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC;IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAAE;AAEzD;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAQpE;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEnD"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Consumer.ts
3
+ * Candidate for inclusion in api-ts
4
+ * Defines a Consumer type that can consume values of type T.
5
+ */
6
+ import { guardFunctions } from "@jonloucks/contracts-ts/api/Types";
7
+ import { presentCheck } from "@jonloucks/contracts-ts/auxiliary/Checks";
8
+ /**
9
+ * Duck type guard check for Consumer
10
+ *
11
+ * @param instance the instance to check
12
+ * @param <T> the type of value consumed
13
+ * @returns true if instance is a Consumer, false otherwise
14
+ */
15
+ export function guard(instance) {
16
+ return guardFunctions(instance, 'consume');
17
+ }
18
+ /**
19
+ * Convert a Type to a Consumer
20
+ *
21
+ * @param type the type to convert
22
+ * @param <T> the type of value consumed
23
+ * @returns a Consumer that consumes values of type T
24
+ */
25
+ export function fromType(type) {
26
+ if (guard(type)) {
27
+ return type;
28
+ }
29
+ else {
30
+ return {
31
+ consume: type
32
+ };
33
+ }
34
+ }
35
+ /**
36
+ * Check that a Consumer is present
37
+ *
38
+ * @param consumer the consumer to check
39
+ * @return the consumer if present
40
+ * @throws IllegalArgumentException if the consumer is not present
41
+ */
42
+ export function check(consumer) {
43
+ return presentCheck(consumer, "Consumer must be present.");
44
+ }
45
+ //# sourceMappingURL=Consumer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Consumer.js","sourceRoot":"","sources":["../../src/auxiliary/Consumer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAgB,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAiBxE;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAI,IAAa;IACvC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO;YACL,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,YAAY,CAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Predicate.ts
3
+ *
4
+ * Candidate for inclusion in api-ts
5
+ * Defines a Predicate type that can test values of type T.
6
+ */
7
+ import { OptionalType, RequiredType } from "@jonloucks/contracts-ts/api/Types";
8
+ /**
9
+ * A method that tests a value of type T and returns a boolean
10
+ */
11
+ export type Method<T> = (value: T) => boolean;
12
+ /**
13
+ * A Predicate that tests values of type T
14
+ */
15
+ export interface Predicate<T> {
16
+ test(value: T): boolean;
17
+ }
18
+ /**
19
+ * A type that can be a Method, Predicate, or a boolean
20
+ */
21
+ export type Type<T> = Method<T> | Predicate<T> | boolean;
22
+ /**
23
+ * Duck type guard check for Predicate
24
+ *
25
+ * @param instance the instance to check
26
+ * @param <T> the type of value tested
27
+ * @returns true if instance is a Predicate, false otherwise
28
+ */
29
+ export declare function guard<T>(instance: unknown): instance is Predicate<T>;
30
+ /**
31
+ * Convert a Type to a Predicate
32
+ *
33
+ * @param type the type to convert
34
+ * @param <T> the type of value tested
35
+ * @returns a Predicate that tests values of type T
36
+ */
37
+ export declare function fromType<T>(type: Type<T>): Predicate<T>;
38
+ /**
39
+ * Test a value against a Predicate Type
40
+ *
41
+ * @param type the Predicate Type
42
+ * @param value the value to test
43
+ * @param <T> the type of value tested
44
+ * @returns true if the value satisfies the Predicate, false otherwise
45
+ */
46
+ export declare function toValue<T>(type: Type<T>, value: T): boolean;
47
+ /**
48
+ * Check that a predicate is present
49
+ *
50
+ * @param predicate the predicate to check
51
+ * @return the predicate if present
52
+ * @throws IllegalArgumentException if the predicate is not present
53
+ */
54
+ export declare function check<T>(predicate: OptionalType<Predicate<T>>): RequiredType<Predicate<T>>;
55
+ //# sourceMappingURL=Predicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Predicate.d.ts","sourceRoot":"","sources":["../../src/auxiliary/Predicate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkB,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAG/F;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC;CAAE;AAE1D;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAEzD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAevD;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAQ3D;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAE1F"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Predicate.ts
3
+ *
4
+ * Candidate for inclusion in api-ts
5
+ * Defines a Predicate type that can test values of type T.
6
+ */
7
+ import { guardFunctions } from "@jonloucks/contracts-ts/api/Types";
8
+ import { presentCheck, used } from "@jonloucks/contracts-ts/auxiliary/Checks";
9
+ /**
10
+ * Duck type guard check for Predicate
11
+ *
12
+ * @param instance the instance to check
13
+ * @param <T> the type of value tested
14
+ * @returns true if instance is a Predicate, false otherwise
15
+ */
16
+ export function guard(instance) {
17
+ return guardFunctions(instance, 'test');
18
+ }
19
+ /**
20
+ * Convert a Type to a Predicate
21
+ *
22
+ * @param type the type to convert
23
+ * @param <T> the type of value tested
24
+ * @returns a Predicate that tests values of type T
25
+ */
26
+ export function fromType(type) {
27
+ if (guard(type)) {
28
+ return type;
29
+ }
30
+ else if (typeof type === 'boolean') {
31
+ return {
32
+ test: (value) => {
33
+ used(value);
34
+ return type;
35
+ }
36
+ };
37
+ }
38
+ else {
39
+ return {
40
+ test: type
41
+ };
42
+ }
43
+ }
44
+ /**
45
+ * Test a value against a Predicate Type
46
+ *
47
+ * @param type the Predicate Type
48
+ * @param value the value to test
49
+ * @param <T> the type of value tested
50
+ * @returns true if the value satisfies the Predicate, false otherwise
51
+ */
52
+ export function toValue(type, value) {
53
+ if (guard(type)) {
54
+ return type.test(value);
55
+ }
56
+ else if (typeof type === 'boolean') {
57
+ return type;
58
+ }
59
+ else {
60
+ return type(value);
61
+ }
62
+ }
63
+ /**
64
+ * Check that a predicate is present
65
+ *
66
+ * @param predicate the predicate to check
67
+ * @return the predicate if present
68
+ * @throws IllegalArgumentException if the predicate is not present
69
+ */
70
+ export function check(predicate) {
71
+ return presentCheck(predicate, "Predicate must be Present.");
72
+ }
73
+ //# sourceMappingURL=Predicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Predicate.js","sourceRoot":"","sources":["../../src/auxiliary/Predicate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAA8B,MAAM,mCAAmC,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAiB9E;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAI,IAAa;IACvC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO;YACL,IAAI,EAAE,CAAC,KAAQ,EAAY,EAAE;gBAC3B,IAAI,CAAC,KAAK,CAAC,CAAC;gBACZ,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO;YACL,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAI,IAAa,EAAE,KAAQ;IAChD,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,SAAqC;IAC5D,OAAO,YAAY,CAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Supplier.ts
3
+ * Candidate for inclusion in api-ts
4
+ * Defines a Supplier type that can supply values of type T.
5
+ */
6
+ import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
7
+ /**
8
+ * A method that supplies a value of type T
9
+ */
10
+ export type Method<T> = () => T;
11
+ /**
12
+ * A Supplier that supplies values of type T
13
+ */
14
+ export interface Supplier<T> {
15
+ supply(): T;
16
+ }
17
+ /**
18
+ * A type that can be a Method, Supplier, or a value of type T
19
+ */
20
+ export type Type<T> = Method<T> | Supplier<T> | T;
21
+ /**
22
+ * Duck type guard check for Supplier
23
+ *
24
+ * @param instance the instance to check
25
+ * @param <T> the type of value supplied
26
+ * @returns true if instance is a Supplier, false otherwise
27
+ */
28
+ export declare function guard<T>(instance: unknown): instance is RequiredType<Supplier<T>>;
29
+ /**
30
+ * Convert a Type to a Supplier
31
+ * @param type the type to convert
32
+ * @param <T> the type of value supplied
33
+ * @returns a Supplier that supplies values of type T
34
+ */
35
+ export declare function fromType<T>(type: Type<T>): RequiredType<Supplier<T>>;
36
+ /**
37
+ * Get the value from a Supplier Type
38
+ *
39
+ * @param type the Supplier Type
40
+ * @param <T> the type of value supplied
41
+ * @returns the value supplied by the Supplier Type
42
+ */
43
+ export declare function toValue<T>(type: Type<T>): T;
44
+ /**
45
+ * Check that a Supplier is present
46
+ *
47
+ * @param supplier the supplier to check
48
+ * @return the supplier if present
49
+ * @throws IllegalArgumentException if the supplier is not present
50
+ */
51
+ export declare function check<T>(supplier: Type<T>): Type<T>;
52
+ //# sourceMappingURL=Supplier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Supplier.d.ts","sourceRoot":"","sources":["../../src/auxiliary/Supplier.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA8B,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAG7F;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEhC;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC;IAAI,MAAM,IAAI,CAAC,CAAC;CAAE;AAE7C;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAElD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAQ3C;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEnD"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Supplier.ts
3
+ * Candidate for inclusion in api-ts
4
+ * Defines a Supplier type that can supply values of type T.
5
+ */
6
+ import { guardFunctions, isFunction } from "@jonloucks/contracts-ts/api/Types";
7
+ import { presentCheck } from "@jonloucks/contracts-ts/auxiliary/Checks";
8
+ /**
9
+ * Duck type guard check for Supplier
10
+ *
11
+ * @param instance the instance to check
12
+ * @param <T> the type of value supplied
13
+ * @returns true if instance is a Supplier, false otherwise
14
+ */
15
+ export function guard(instance) {
16
+ return guardFunctions(instance, 'supply');
17
+ }
18
+ /**
19
+ * Convert a Type to a Supplier
20
+ * @param type the type to convert
21
+ * @param <T> the type of value supplied
22
+ * @returns a Supplier that supplies values of type T
23
+ */
24
+ export function fromType(type) {
25
+ if (guard(type)) {
26
+ return type;
27
+ }
28
+ else if (isFunction(type)) {
29
+ return {
30
+ supply: type
31
+ };
32
+ }
33
+ else {
34
+ return {
35
+ supply: () => type
36
+ };
37
+ }
38
+ }
39
+ /**
40
+ * Get the value from a Supplier Type
41
+ *
42
+ * @param type the Supplier Type
43
+ * @param <T> the type of value supplied
44
+ * @returns the value supplied by the Supplier Type
45
+ */
46
+ export function toValue(type) {
47
+ if (guard(type)) {
48
+ return type.supply();
49
+ }
50
+ else if (isFunction(type)) {
51
+ return type();
52
+ }
53
+ else {
54
+ return type;
55
+ }
56
+ }
57
+ /**
58
+ * Check that a Supplier is present
59
+ *
60
+ * @param supplier the supplier to check
61
+ * @return the supplier if present
62
+ * @throws IllegalArgumentException if the supplier is not present
63
+ */
64
+ export function check(supplier) {
65
+ return presentCheck(supplier, "Supplier must be Present.");
66
+ }
67
+ //# sourceMappingURL=Supplier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Supplier.js","sourceRoot":"","sources":["../../src/auxiliary/Supplier.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAgB,MAAM,mCAAmC,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAiBxE;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAI,IAAa;IACvC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO;YACL,MAAM,EAAE,IAAI;SACb,CAAA;IACH,CAAC;SAAM,CAAC;QACN,OAAO;YACL,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI;SACnB,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAI,IAAa;IACtC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;SAAM,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,YAAY,CAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Completable, Config } from "@jonloucks/concurrency-ts/api/Completable";
2
+ /**
3
+ * Create a new Completable
4
+ *
5
+ * @param config the completable configuration
6
+ * @return the new Completable
7
+ * @param <T> the type of completion value
8
+ */
9
+ export declare function create<T>(config: Config<T>): Completable<T>;
10
+ //# sourceMappingURL=Completable.impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Completable.impl.d.ts","sourceRoot":"","sources":["../../src/impl/Completable.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAoBhF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAE3D"}
@@ -0,0 +1,136 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _CompletableImpl_completionStateMachine, _CompletableImpl_idempotent, _CompletableImpl_completion, _CompletableImpl_waitableValue, _CompletableImpl_closeMany, _CompletableImpl_observers;
13
+ import { getStateMachineConfig as getCompletionStateConfig } from "@jonloucks/concurrency-ts/api/CompletionState";
14
+ import { completionCheck, onCompletionCheck } from "@jonloucks/concurrency-ts/auxiliary/Checks";
15
+ import { inlineAutoClose } from "@jonloucks/contracts-ts/api/AutoClose";
16
+ import { contractsCheck } from "@jonloucks/contracts-ts/auxiliary/Checks";
17
+ import { createAtomicBoolean, createIdempotent } from "@jonloucks/contracts-ts/auxiliary/Convenience";
18
+ import { IllegalStateException } from "@jonloucks/contracts-ts/auxiliary/IllegalStateException";
19
+ import { create as createStateMachine } from "./StateMachine.impl.js";
20
+ import { create as createWaitable } from "./Waitable.impl.js";
21
+ import { isPresent } from "@jonloucks/contracts-ts/api/Types";
22
+ import { CONTRACT as AUTO_CLOSE_FACTORY } from "@jonloucks/contracts-ts/api/AutoCloseFactory";
23
+ /**
24
+ * Create a new Completable
25
+ *
26
+ * @param config the completable configuration
27
+ * @return the new Completable
28
+ * @param <T> the type of completion value
29
+ */
30
+ export function create(config) {
31
+ return CompletableImpl.internalCreate(config);
32
+ }
33
+ ;
34
+ class CompletableImpl {
35
+ open() {
36
+ return __classPrivateFieldGet(this, _CompletableImpl_idempotent, "f").open();
37
+ }
38
+ notifyState() {
39
+ return __classPrivateFieldGet(this, _CompletableImpl_completionStateMachine, "f");
40
+ }
41
+ notifyValue() {
42
+ return __classPrivateFieldGet(this, _CompletableImpl_waitableValue, "f");
43
+ }
44
+ getCompletion() {
45
+ return __classPrivateFieldGet(this, _CompletableImpl_completion, "f");
46
+ }
47
+ notify(onCompletion) {
48
+ const referentOnCompletion = onCompletionCheck(onCompletion);
49
+ const firstClose = createAtomicBoolean(true);
50
+ const isLive = createAtomicBoolean(true);
51
+ const removeObserver = (v) => {
52
+ __classPrivateFieldGet(this, _CompletableImpl_observers, "f").delete(v);
53
+ };
54
+ const observer = {
55
+ onCompletion: function (completion) {
56
+ if (isLive.get()) {
57
+ referentOnCompletion.onCompletion(completion);
58
+ }
59
+ },
60
+ close: function () {
61
+ if (firstClose.compareAndSet(true, false)) {
62
+ isLive.set(false);
63
+ removeObserver(this);
64
+ }
65
+ }
66
+ };
67
+ __classPrivateFieldGet(this, _CompletableImpl_observers, "f").add(observer);
68
+ if (isPresent(__classPrivateFieldGet(this, _CompletableImpl_completion, "f"))) {
69
+ try {
70
+ observer.onCompletion(__classPrivateFieldGet(this, _CompletableImpl_completion, "f"));
71
+ }
72
+ catch (e) {
73
+ removeObserver(observer);
74
+ throw e;
75
+ }
76
+ }
77
+ return inlineAutoClose(() => {
78
+ observer.close();
79
+ });
80
+ }
81
+ onCompletion(completion) {
82
+ const validCompletion = completionCheck(completion);
83
+ this.assertNotRejecting();
84
+ if (__classPrivateFieldGet(this, _CompletableImpl_completionStateMachine, "f").setState("onCompletion", validCompletion.state)) {
85
+ __classPrivateFieldSet(this, _CompletableImpl_completion, validCompletion, "f");
86
+ const value = validCompletion.value;
87
+ if (this.isCompleted() && isPresent(value)) {
88
+ __classPrivateFieldGet(this, _CompletableImpl_waitableValue, "f").consume(value);
89
+ }
90
+ this.notifyObservers(validCompletion);
91
+ }
92
+ }
93
+ isCompleted() {
94
+ return __classPrivateFieldGet(this, _CompletableImpl_completionStateMachine, "f").isCompleted();
95
+ }
96
+ realOpen() {
97
+ __classPrivateFieldGet(this, _CompletableImpl_closeMany, "f").add(__classPrivateFieldGet(this, _CompletableImpl_waitableValue, "f").open());
98
+ __classPrivateFieldGet(this, _CompletableImpl_closeMany, "f").add(__classPrivateFieldGet(this, _CompletableImpl_completionStateMachine, "f").open());
99
+ return inlineAutoClose(() => {
100
+ __classPrivateFieldGet(this, _CompletableImpl_closeMany, "f").close();
101
+ });
102
+ }
103
+ notifyObservers(newValue) {
104
+ for (const observer of __classPrivateFieldGet(this, _CompletableImpl_observers, "f")) {
105
+ observer.onCompletion(newValue);
106
+ }
107
+ }
108
+ assertNotRejecting() {
109
+ switch (__classPrivateFieldGet(this, _CompletableImpl_idempotent, "f").getState()) {
110
+ case 'OPENABLE':
111
+ case 'DESTROYED':
112
+ case 'CLOSED':
113
+ throw new IllegalStateException("Completable is rejecting.");
114
+ }
115
+ }
116
+ static internalCreate(config) {
117
+ return new CompletableImpl(config);
118
+ }
119
+ constructor(config) {
120
+ _CompletableImpl_completionStateMachine.set(this, void 0);
121
+ _CompletableImpl_idempotent.set(this, void 0);
122
+ _CompletableImpl_completion.set(this, null);
123
+ _CompletableImpl_waitableValue.set(this, void 0);
124
+ _CompletableImpl_closeMany.set(this, void 0);
125
+ _CompletableImpl_observers.set(this, new Set());
126
+ const contracts = contractsCheck(config.contracts);
127
+ const closeFactory = contracts.enforce(AUTO_CLOSE_FACTORY);
128
+ __classPrivateFieldSet(this, _CompletableImpl_closeMany, closeFactory.createAutoCloseMany(), "f");
129
+ __classPrivateFieldSet(this, _CompletableImpl_waitableValue, createWaitable({ contracts: contracts, initialValue: config.initialValue }), "f");
130
+ __classPrivateFieldSet(this, _CompletableImpl_idempotent, createIdempotent({ contracts: contracts, open: () => this.realOpen() }), "f");
131
+ __classPrivateFieldSet(this, _CompletableImpl_completionStateMachine, createStateMachine(getCompletionStateConfig()), "f");
132
+ }
133
+ }
134
+ _CompletableImpl_completionStateMachine = new WeakMap(), _CompletableImpl_idempotent = new WeakMap(), _CompletableImpl_completion = new WeakMap(), _CompletableImpl_waitableValue = new WeakMap(), _CompletableImpl_closeMany = new WeakMap(), _CompletableImpl_observers = new WeakMap();
135
+ ;
136
+ //# sourceMappingURL=Completable.impl.js.map