reactor-core-ts 2.1.6 → 3.2.1

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 (269) hide show
  1. package/README.md +927 -658
  2. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js +12 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPrimitive.js +14 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPropertyKey.js +9 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/typeof.js +11 -0
  6. package/dist/context/context-view.d.ts +31 -0
  7. package/dist/context/context-view.d.ts.map +1 -0
  8. package/dist/context/context-view.js +58 -0
  9. package/dist/context/context-view.js.map +1 -0
  10. package/dist/context/context.d.ts +46 -0
  11. package/dist/context/context.d.ts.map +1 -0
  12. package/dist/context/context.js +125 -0
  13. package/dist/context/context.js.map +1 -0
  14. package/dist/context/types.d.ts +7 -0
  15. package/dist/context/types.d.ts.map +1 -0
  16. package/dist/core/boolean-disposable.d.ts +19 -0
  17. package/dist/core/boolean-disposable.d.ts.map +1 -0
  18. package/dist/core/boolean-disposable.js +37 -0
  19. package/dist/core/boolean-disposable.js.map +1 -0
  20. package/dist/core/composite-disposable.d.ts +21 -0
  21. package/dist/core/composite-disposable.d.ts.map +1 -0
  22. package/dist/core/composite-disposable.js +64 -0
  23. package/dist/core/composite-disposable.js.map +1 -0
  24. package/dist/core/demand.d.ts +9 -0
  25. package/dist/core/demand.d.ts.map +1 -0
  26. package/dist/core/demand.js +21 -0
  27. package/dist/core/demand.js.map +1 -0
  28. package/dist/core/disposables.d.ts +12 -0
  29. package/dist/core/disposables.d.ts.map +1 -0
  30. package/dist/core/disposables.js +37 -0
  31. package/dist/core/disposables.js.map +1 -0
  32. package/dist/core/teardown.d.ts +4 -0
  33. package/dist/core/teardown.d.ts.map +1 -0
  34. package/dist/core/types.d.ts +14 -0
  35. package/dist/core/types.d.ts.map +1 -0
  36. package/dist/errors/classes.d.ts +37 -0
  37. package/dist/errors/classes.d.ts.map +1 -0
  38. package/dist/errors/classes.js +53 -0
  39. package/dist/errors/classes.js.map +1 -0
  40. package/dist/errors/exceptions.d.ts +15 -0
  41. package/dist/errors/exceptions.d.ts.map +1 -0
  42. package/dist/errors/helpers.d.ts +9 -0
  43. package/dist/errors/helpers.d.ts.map +1 -0
  44. package/dist/errors/helpers.js +18 -0
  45. package/dist/errors/helpers.js.map +1 -0
  46. package/dist/index.d.ts +17 -2556
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +8 -2
  49. package/dist/internal/abort.d.ts +5 -0
  50. package/dist/internal/abort.d.ts.map +1 -0
  51. package/dist/internal/abort.js +36 -0
  52. package/dist/internal/abort.js.map +1 -0
  53. package/dist/internal/async-queue.d.ts +48 -0
  54. package/dist/internal/async-queue.d.ts.map +1 -0
  55. package/dist/internal/async-queue.js +187 -0
  56. package/dist/internal/async-queue.js.map +1 -0
  57. package/dist/internal/iterable-terminal.d.ts +12 -0
  58. package/dist/internal/iterable-terminal.d.ts.map +1 -0
  59. package/dist/internal/iterable-terminal.js +49 -0
  60. package/dist/internal/iterable-terminal.js.map +1 -0
  61. package/dist/internal/iterable-transform.d.ts +24 -0
  62. package/dist/internal/iterable-transform.d.ts.map +1 -0
  63. package/dist/internal/iterable-transform.js +159 -0
  64. package/dist/internal/iterable-transform.js.map +1 -0
  65. package/dist/internal/iterable.d.ts +23 -0
  66. package/dist/internal/iterable.d.ts.map +1 -0
  67. package/dist/internal/iterable.js +81 -0
  68. package/dist/internal/iterable.js.map +1 -0
  69. package/dist/internal/microtask.d.ts +7 -0
  70. package/dist/internal/microtask.d.ts.map +1 -0
  71. package/dist/internal/microtask.js +19 -0
  72. package/dist/internal/microtask.js.map +1 -0
  73. package/dist/publisher/browser-sources.d.ts +15 -0
  74. package/dist/publisher/browser-sources.d.ts.map +1 -0
  75. package/dist/publisher/browser-sources.js +92 -0
  76. package/dist/publisher/browser-sources.js.map +1 -0
  77. package/dist/publisher/flux-entrypoint.d.ts +7 -0
  78. package/dist/publisher/flux-entrypoint.d.ts.map +1 -0
  79. package/dist/publisher/flux-entrypoint.js +11 -0
  80. package/dist/publisher/flux-entrypoint.js.map +1 -0
  81. package/dist/publisher/flux.d.ts +121 -0
  82. package/dist/publisher/flux.d.ts.map +1 -0
  83. package/dist/publisher/flux.js +697 -0
  84. package/dist/publisher/flux.js.map +1 -0
  85. package/dist/publisher/helpers.d.ts +19 -0
  86. package/dist/publisher/helpers.d.ts.map +1 -0
  87. package/dist/publisher/helpers.js +84 -0
  88. package/dist/publisher/helpers.js.map +1 -0
  89. package/dist/publisher/mono-entrypoint.d.ts +7 -0
  90. package/dist/publisher/mono-entrypoint.d.ts.map +1 -0
  91. package/dist/publisher/mono-entrypoint.js +11 -0
  92. package/dist/publisher/mono-entrypoint.js.map +1 -0
  93. package/dist/publisher/mono.d.ts +72 -0
  94. package/dist/publisher/mono.d.ts.map +1 -0
  95. package/dist/publisher/mono.js +373 -0
  96. package/dist/publisher/mono.js.map +1 -0
  97. package/dist/publisher/operators/aggregate.d.ts +35 -0
  98. package/dist/publisher/operators/aggregate.d.ts.map +1 -0
  99. package/dist/publisher/operators/aggregate.js +217 -0
  100. package/dist/publisher/operators/aggregate.js.map +1 -0
  101. package/dist/publisher/operators/compat/flux.d.ts +56 -0
  102. package/dist/publisher/operators/compat/flux.d.ts.map +1 -0
  103. package/dist/publisher/operators/compat/flux.js +156 -0
  104. package/dist/publisher/operators/compat/flux.js.map +1 -0
  105. package/dist/publisher/operators/compat/mono.d.ts +82 -0
  106. package/dist/publisher/operators/compat/mono.d.ts.map +1 -0
  107. package/dist/publisher/operators/compat/mono.js +125 -0
  108. package/dist/publisher/operators/compat/mono.js.map +1 -0
  109. package/dist/publisher/operators/coordination.d.ts +82 -0
  110. package/dist/publisher/operators/coordination.d.ts.map +1 -0
  111. package/dist/publisher/operators/coordination.js +345 -0
  112. package/dist/publisher/operators/coordination.js.map +1 -0
  113. package/dist/publisher/operators/error.d.ts +17 -0
  114. package/dist/publisher/operators/error.d.ts.map +1 -0
  115. package/dist/publisher/operators/error.js +48 -0
  116. package/dist/publisher/operators/error.js.map +1 -0
  117. package/dist/publisher/operators/flatten.d.ts +19 -0
  118. package/dist/publisher/operators/flatten.d.ts.map +1 -0
  119. package/dist/publisher/operators/flatten.js +127 -0
  120. package/dist/publisher/operators/flatten.js.map +1 -0
  121. package/dist/publisher/operators/lifecycle.d.ts +103 -0
  122. package/dist/publisher/operators/lifecycle.d.ts.map +1 -0
  123. package/dist/publisher/operators/lifecycle.js +237 -0
  124. package/dist/publisher/operators/lifecycle.js.map +1 -0
  125. package/dist/publisher/operators/mono-parity.d.ts +109 -0
  126. package/dist/publisher/operators/mono-parity.d.ts.map +1 -0
  127. package/dist/publisher/operators/mono-parity.js +144 -0
  128. package/dist/publisher/operators/mono-parity.js.map +1 -0
  129. package/dist/publisher/operators/mono.d.ts +30 -0
  130. package/dist/publisher/operators/mono.d.ts.map +1 -0
  131. package/dist/publisher/operators/mono.js +37 -0
  132. package/dist/publisher/operators/mono.js.map +1 -0
  133. package/dist/publisher/operators/register.d.ts +20 -0
  134. package/dist/publisher/operators/register.d.ts.map +1 -0
  135. package/dist/publisher/operators/register.js +23 -0
  136. package/dist/publisher/operators/register.js.map +1 -0
  137. package/dist/publisher/operators/selection.d.ts +25 -0
  138. package/dist/publisher/operators/selection.d.ts.map +1 -0
  139. package/dist/publisher/operators/selection.js +108 -0
  140. package/dist/publisher/operators/selection.js.map +1 -0
  141. package/dist/publisher/operators/side-effect.d.ts +15 -0
  142. package/dist/publisher/operators/side-effect.d.ts.map +1 -0
  143. package/dist/publisher/operators/side-effect.js +56 -0
  144. package/dist/publisher/operators/side-effect.js.map +1 -0
  145. package/dist/publisher/operators/terminal.d.ts +16 -0
  146. package/dist/publisher/operators/terminal.d.ts.map +1 -0
  147. package/dist/publisher/operators/terminal.js +47 -0
  148. package/dist/publisher/operators/terminal.js.map +1 -0
  149. package/dist/publisher/operators/time.d.ts +20 -0
  150. package/dist/publisher/operators/time.d.ts.map +1 -0
  151. package/dist/publisher/operators/time.js +92 -0
  152. package/dist/publisher/operators/time.js.map +1 -0
  153. package/dist/publisher/operators/transform.d.ts +31 -0
  154. package/dist/publisher/operators/transform.d.ts.map +1 -0
  155. package/dist/publisher/operators/transform.js +74 -0
  156. package/dist/publisher/operators/transform.js.map +1 -0
  157. package/dist/publisher/operators/windowing.d.ts +28 -0
  158. package/dist/publisher/operators/windowing.d.ts.map +1 -0
  159. package/dist/publisher/operators/windowing.js +148 -0
  160. package/dist/publisher/operators/windowing.js.map +1 -0
  161. package/dist/publisher/publisher.d.ts +11 -0
  162. package/dist/publisher/publisher.d.ts.map +1 -0
  163. package/dist/publisher/types.d.ts +51 -0
  164. package/dist/publisher/types.d.ts.map +1 -0
  165. package/dist/schedulers/animation-frame-scheduler.d.ts +11 -0
  166. package/dist/schedulers/animation-frame-scheduler.d.ts.map +1 -0
  167. package/dist/schedulers/animation-frame-scheduler.js +30 -0
  168. package/dist/schedulers/animation-frame-scheduler.js.map +1 -0
  169. package/dist/schedulers/base-scheduler.d.ts +28 -0
  170. package/dist/schedulers/base-scheduler.d.ts.map +1 -0
  171. package/dist/schedulers/base-scheduler.js +77 -0
  172. package/dist/schedulers/base-scheduler.js.map +1 -0
  173. package/dist/schedulers/basic-worker.d.ts +22 -0
  174. package/dist/schedulers/basic-worker.d.ts.map +1 -0
  175. package/dist/schedulers/basic-worker.js +71 -0
  176. package/dist/schedulers/basic-worker.js.map +1 -0
  177. package/dist/schedulers/delay-scheduler.d.ts +12 -0
  178. package/dist/schedulers/delay-scheduler.d.ts.map +1 -0
  179. package/dist/schedulers/delay-scheduler.js +17 -0
  180. package/dist/schedulers/delay-scheduler.js.map +1 -0
  181. package/dist/schedulers/disposed.d.ts +4 -0
  182. package/dist/schedulers/disposed.d.ts.map +1 -0
  183. package/dist/schedulers/disposed.js +14 -0
  184. package/dist/schedulers/disposed.js.map +1 -0
  185. package/dist/schedulers/duration.d.ts +8 -0
  186. package/dist/schedulers/duration.d.ts.map +1 -0
  187. package/dist/schedulers/duration.js +11 -0
  188. package/dist/schedulers/duration.js.map +1 -0
  189. package/dist/schedulers/executor-scheduler.d.ts +13 -0
  190. package/dist/schedulers/executor-scheduler.d.ts.map +1 -0
  191. package/dist/schedulers/executor-scheduler.js +43 -0
  192. package/dist/schedulers/executor-scheduler.js.map +1 -0
  193. package/dist/schedulers/immediate-scheduler.d.ts +15 -0
  194. package/dist/schedulers/immediate-scheduler.d.ts.map +1 -0
  195. package/dist/schedulers/immediate-scheduler.js +24 -0
  196. package/dist/schedulers/immediate-scheduler.js.map +1 -0
  197. package/dist/schedulers/index.d.ts +7 -0
  198. package/dist/schedulers/index.d.ts.map +1 -0
  199. package/dist/schedulers/index.js +2 -0
  200. package/dist/schedulers/interval-scheduler.d.ts +12 -0
  201. package/dist/schedulers/interval-scheduler.d.ts.map +1 -0
  202. package/dist/schedulers/interval-scheduler.js +17 -0
  203. package/dist/schedulers/interval-scheduler.js.map +1 -0
  204. package/dist/schedulers/macro-scheduler.d.ts +19 -0
  205. package/dist/schedulers/macro-scheduler.d.ts.map +1 -0
  206. package/dist/schedulers/macro-scheduler.js +30 -0
  207. package/dist/schedulers/macro-scheduler.js.map +1 -0
  208. package/dist/schedulers/microtask-scheduler.d.ts +11 -0
  209. package/dist/schedulers/microtask-scheduler.d.ts.map +1 -0
  210. package/dist/schedulers/microtask-scheduler.js +34 -0
  211. package/dist/schedulers/microtask-scheduler.js.map +1 -0
  212. package/dist/schedulers/schedulers.d.ts +39 -0
  213. package/dist/schedulers/schedulers.d.ts.map +1 -0
  214. package/dist/schedulers/schedulers.js +83 -0
  215. package/dist/schedulers/schedulers.js.map +1 -0
  216. package/dist/schedulers/timeout-scheduler.d.ts +11 -0
  217. package/dist/schedulers/timeout-scheduler.d.ts.map +1 -0
  218. package/dist/schedulers/types.d.ts +35 -0
  219. package/dist/schedulers/types.d.ts.map +1 -0
  220. package/dist/signal/signal-type.d.ts +26 -0
  221. package/dist/signal/signal-type.d.ts.map +1 -0
  222. package/dist/signal/signal-type.js +31 -0
  223. package/dist/signal/signal-type.js.map +1 -0
  224. package/dist/signal/signal.d.ts +33 -0
  225. package/dist/signal/signal.d.ts.map +1 -0
  226. package/dist/signal/signal.js +70 -0
  227. package/dist/signal/signal.js.map +1 -0
  228. package/dist/sinks/index.d.ts +7 -0
  229. package/dist/sinks/index.d.ts.map +1 -0
  230. package/dist/sinks/index.js +2 -0
  231. package/dist/sinks/many.d.ts +66 -0
  232. package/dist/sinks/many.d.ts.map +1 -0
  233. package/dist/sinks/many.js +193 -0
  234. package/dist/sinks/many.js.map +1 -0
  235. package/dist/sinks/one.d.ts +41 -0
  236. package/dist/sinks/one.d.ts.map +1 -0
  237. package/dist/sinks/one.js +144 -0
  238. package/dist/sinks/one.js.map +1 -0
  239. package/dist/sinks/specs.d.ts +25 -0
  240. package/dist/sinks/specs.d.ts.map +1 -0
  241. package/dist/sinks/specs.js +126 -0
  242. package/dist/sinks/specs.js.map +1 -0
  243. package/dist/sinks/subscribers.d.ts +16 -0
  244. package/dist/sinks/subscribers.d.ts.map +1 -0
  245. package/dist/sinks/subscribers.js +32 -0
  246. package/dist/sinks/subscribers.js.map +1 -0
  247. package/dist/sinks/types.d.ts +137 -0
  248. package/dist/sinks/types.d.ts.map +1 -0
  249. package/dist/sinks/types.js +58 -0
  250. package/dist/sinks/types.js.map +1 -0
  251. package/dist/subscription/core-subscriber.d.ts +12 -0
  252. package/dist/subscription/core-subscriber.d.ts.map +1 -0
  253. package/dist/subscription/iterable-subscription.d.ts +64 -0
  254. package/dist/subscription/iterable-subscription.d.ts.map +1 -0
  255. package/dist/subscription/iterable-subscription.js +281 -0
  256. package/dist/subscription/iterable-subscription.js.map +1 -0
  257. package/dist/subscription/reactive-streams.d.ts +8 -0
  258. package/dist/subscription/reactive-streams.d.ts.map +1 -0
  259. package/dist/subscription/reactive-streams.js +0 -0
  260. package/dist/subscription/subscriber.d.ts +17 -0
  261. package/dist/subscription/subscriber.d.ts.map +1 -0
  262. package/dist/subscription/subscription.d.ts +12 -0
  263. package/dist/subscription/subscription.d.ts.map +1 -0
  264. package/package.json +99 -33
  265. package/LICENSE.md +0 -56
  266. package/dist/index.d.mts +0 -2557
  267. package/dist/index.js.map +0 -1
  268. package/dist/index.mjs +0 -2
  269. package/dist/index.mjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,2557 +1,18 @@
1
1
  /**
2
- * Represents a subscription to a Publisher.
3
- * Manages the flow of data and provides the ability to cancel the subscription.
4
- */
5
- interface Subscription {
6
- /**
7
- * Requests a specified number of items from the Publisher.
8
- * Allows controlling backpressure by specifying how many items to emit.
9
- * @param {number} count - The number of items to request from the Publisher.
10
- */
11
- request(count: number): void;
12
- /**
13
- * Cancels the subscription, stopping any further emissions.
14
- * Unsubscribing releases resources associated with the subscription.
15
- */
16
- unsubscribe(): void;
17
- }
18
-
19
- /**
20
- * Represents a subscriber that listens to events emitted by a Publisher.
21
- *
22
- * Reactive Streams spec: the Publisher MUST call onSubscribe before any other signal.
23
- * The Subscriber SHOULD call Subscription.request(n) from within onSubscribe.
24
- *
25
- * @template T - The type of data that the subscriber will receive.
26
- */
27
- interface Subscriber<T> {
28
- /**
29
- * Called once by the Publisher immediately after subscribe().
30
- * MUST be called before onNext, onError, or onComplete.
31
- * @param {Subscription} subscription - The subscription controlling demand and cancellation.
32
- */
33
- onSubscribe(subscription: Subscription): void;
34
- /**
35
- * Called when the next item is emitted.
36
- * @param {T} value - The next value emitted by the Publisher.
37
- */
38
- onNext(value: T): void;
39
- /**
40
- * Called when an error occurs during data emission.
41
- * @param {Error} error - The error encountered.
42
- */
43
- onError(error: Error): void;
44
- /**
45
- * Called when the Publisher has successfully completed emitting all items.
46
- */
47
- onComplete(): void;
48
- }
49
-
50
- /**
51
- * Represents a generic publisher that can subscribe to a data stream.
52
- * @template T - The type of data being published.
53
- */
54
- interface Publisher<T> {
55
- /**
56
- * Subscribes a subscriber to the publisher.
57
- * @param {Subscriber<T>} subscriber - The subscriber to receive published data.
58
- * @returns {Subscription} A subscription object to manage the subscriber's lifecycle.
59
- */
60
- subscribe(subscriber: Subscriber<T>): Subscription;
61
- }
62
-
63
- /**
64
- * Represents a sink that consumes emitted values, errors, and completion signals.
65
- * Typically used as the endpoint in a reactive stream to receive and handle data.
66
- *
67
- * @template T - The type of data being consumed.
68
- */
69
- interface Sink<T> {
70
- /**
71
- * Consumes the next emitted value.
72
- * Called when a new value is pushed to the sink.
73
- * @param {T} value - The value to be processed.
74
- */
75
- next(value: T): void;
76
- /**
77
- * Handles an error emitted during the data stream.
78
- * Called when an error occurs within the publisher.
79
- * @param {Error} error - The error encountered.
80
- */
81
- error(error: Error): void;
82
- /**
83
- * Signals the completion of the data stream.
84
- * Called when the publisher has finished emitting all values.
85
- */
86
- complete(): void;
87
- }
88
-
89
- /**
90
- * Represents a basic scheduling interface for executing tasks.
91
- */
92
- interface Scheduler {
93
- /**
94
- * Schedules a task to be executed.
95
- * @param {Function} task - The task function to be executed.
96
- */
97
- schedule(task: () => void): void;
98
- }
99
- /**
100
- * Represents a cancellable scheduling interface, extending the basic `Scheduler` interface.
101
- * Provides the ability to cancel a scheduled task.
102
- */
103
- interface CancellableScheduler extends Scheduler {
104
- /**
105
- * Schedules a task to be executed with the ability to cancel it.
106
- * @param {Function} task - The task function to be executed.
107
- * @returns {Object} An object containing a `cancel` method to stop the execution.
108
- */
109
- schedule(task: () => void): {
110
- cancel: () => void;
111
- };
112
- }
113
-
114
- /**
115
- * An interface representing a publisher that supports data transformation and manipulation through pipes.
116
- * @template T - The type of data being published.
117
- */
118
- interface PipePublisher<T> extends Publisher<T> {
119
- /**
120
- * Pipes the data through custom transformations.
121
- * @template R - The result type after processing.
122
- * @param {Function} producer - The function to produce new values.
123
- * @param {Function} onSubscribe - Callback on subscription.
124
- * @param {Function} onRequest - Callback on request.
125
- * @param {Function} onUnsubscribe - Callback on unsubscribe.
126
- * @returns {PipePublisher<R>} A new pipe publisher with transformed data.
127
- */
128
- pipe<R>(producer: (onNext: (value: R) => void, onError: (error: Error) => void, onComplete: () => void) => void, onRequest: (request: number) => void, onUnsubscribe: () => void): PipePublisher<R>;
129
- /**
130
- * Transforms each emitted value using the given function.
131
- * @template R - The transformed data type.
132
- * @param {Function} fn - The mapping function.
133
- * @returns {PipePublisher<R>} A new pipe publisher with mapped data.
134
- */
135
- map<R>(fn: (value: T) => R): PipePublisher<R>;
136
- /**
137
- * Transforms each emitted value and filter transform result.
138
- * @template R - The transformed data type.
139
- * @param {Function} fn - The mapping function that can return null or undefined.
140
- * @returns {PipePublisher<R>} A new pipe publisher with mapped non-null data.
141
- */
142
- mapNotNull<R>(fn: (value: T) => R | null | undefined): PipePublisher<R>;
143
- /**
144
- * Transforms the value using a function that returns a new publisher.
145
- * @template R - The resulting data type.
146
- * @param {Function} fn - The function to transform values into new publishers.
147
- * @returns {PipePublisher<R>} A pipe publisher that flattens the result.
148
- */
149
- flatMap<R>(fn: (value: T) => Publisher<R>): PipePublisher<R>;
150
- /**
151
- * Filters emitted values using a given predicate.
152
- * @param {Function} predicate - The function to determine whether to emit a value.
153
- * @returns {PipePublisher<T>} A new pipe publisher with filtered data.
154
- */
155
- filter(predicate: (value: T) => boolean): PipePublisher<T>;
156
- /**
157
- * Filters emitted values based on a publisher that returns a boolean.
158
- * @param {Function} predicate - A function returning a boolean publisher.
159
- * @returns {PipePublisher<T>} A new pipe publisher with conditional data.
160
- */
161
- filterWhen(predicate: (value: T) => Publisher<boolean>): PipePublisher<T>;
162
- /**
163
- * Casts the current publisher to another type.
164
- * @template R - The target type.
165
- * @returns {PipePublisher<R>} The casted pipe publisher.
166
- */
167
- cast<R>(): PipePublisher<R>;
168
- /**
169
- * Switches to an alternative publisher if the current one is empty.
170
- * @param {Publisher<T>} alternative - The alternative publisher.
171
- * @returns {PipePublisher<T>} A new pipe publisher.
172
- */
173
- switchIfEmpty(alternative: Publisher<T>): PipePublisher<T>;
174
- /**
175
- * Continues with a replacement publisher if an error occurs.
176
- * @param {Publisher<T>} replacement - The publisher to switch to on error.
177
- * @returns {PipePublisher<T>} A new pipe publisher.
178
- */
179
- onErrorReturn(replacement: Publisher<T>): PipePublisher<T>;
180
- /**
181
- * Continues processing even if an error occurs based on a predicate.
182
- * @param {Function} predicate - Function to determine whether to continue on error.
183
- * @returns {PipePublisher<T>} A new pipe publisher.
184
- */
185
- onErrorContinue(predicate: (error: Error) => boolean): PipePublisher<T>;
186
- /**
187
- * Executes a function when the first value is emitted.
188
- * @param {Function} fn - The function to execute.
189
- * @returns {PipePublisher<T>} A new pipe publisher.
190
- */
191
- doFirst(fn: () => void): PipePublisher<T>;
192
- /**
193
- * Executes a function when each value is emitted.
194
- * @param {Function} fn - The function to execute on each value.
195
- * @returns {PipePublisher<T>} A new pipe publisher.
196
- */
197
- doOnNext(fn: (value: T) => void): PipePublisher<T>;
198
- /**
199
- * Executes a function when each error is emitted.
200
- * @param {Function} fn - The function to execute on each error.
201
- * @returns {PipePublisher<T>} A new pipe publisher.
202
- */
203
- doOnError(fn: (value: Error) => void): PipePublisher<T>;
204
- /**
205
- * Executes a function when the stream completes.
206
- * @param {Function} fn - The function to execute on completion.
207
- * @returns {PipePublisher<T>} A new pipe publisher.
208
- */
209
- doFinally(fn: () => void): PipePublisher<T>;
210
- /**
211
- * Executes a function when a subscription occurs.
212
- * @param {Function} fn - The function to execute on subscription.
213
- * @returns {PipePublisher<T>} A new pipe publisher.
214
- */
215
- doOnSubscribe(fn: (subscription: Subscription) => void): PipePublisher<T>;
216
- /**
217
- * Publishes values on a specified scheduler.
218
- * @param {Scheduler} scheduler - The scheduler to use.
219
- * @returns {PipePublisher<T>} A new pipe publisher.
220
- */
221
- publishOn(scheduler: Scheduler): PipePublisher<T>;
222
- /**
223
- * Subscribes to the stream on a specified scheduler.
224
- * @param {Scheduler} scheduler - The scheduler to use.
225
- * @returns {PipePublisher<T>} A new pipe publisher.
226
- */
227
- subscribeOn(scheduler: Scheduler): PipePublisher<T>;
228
- }
229
-
230
- /**
231
- * Represents a reactive signal — one of the three events that can be emitted
232
- * by a {@link Publisher}: a value (`next`), a terminal error (`error`), or
233
- * a normal completion (`complete`).
234
- *
235
- * `Signal` is the type used by {@link Flux#materialize} /
236
- * {@link Flux#dematerialize} to pass reactive events as plain data values.
237
- *
238
- * @typeParam T - The type of the value carried by a `next` signal.
239
- */
240
- type Signal<T> = {
241
- readonly kind: 'next';
242
- readonly value: T;
243
- } | {
244
- readonly kind: 'error';
245
- readonly error: Error;
246
- } | {
247
- readonly kind: 'complete';
248
- };
249
- /**
250
- * Namespace of factory helpers for creating {@link Signal} instances.
251
- */
252
- declare const Signal: {
253
- /**
254
- * Creates a `next` signal carrying `value`.
255
- * @param value - The item to wrap.
256
- */
257
- next<T>(value: T): Signal<T>;
258
- /**
259
- * Creates an `error` signal carrying `error`.
260
- * @param error - The error to wrap.
261
- */
262
- error<T>(error: Error): Signal<T>;
263
- /**
264
- * Creates a `complete` signal.
265
- */
266
- complete<T>(): Signal<T>;
267
- };
268
-
269
- /**
270
- * Base class for Flux and Mono providing the common operator implementations
271
- * that are identical across both types. Operators that preserve T use the
272
- * abstract `wrapSource` factory so that subclasses always return their own
273
- * concrete type (Flux → Flux, Mono → Mono) without any unsafe casts at
274
- * call-sites.
275
- *
276
- * Operators NOT included here (different semantics or change the type):
277
- * - filter / filterWhen — demand-replenishment differs between Flux and Mono
278
- * - doFinally — Flux also fires fn on cancel; Mono does not
279
- * - map / flatMap / cast / pipe / mapNotNull — change the type T → R
280
- */
281
- declare abstract class AbstractPipePublisher<T, Self> implements Publisher<T> {
282
- protected readonly source: Publisher<T>;
283
- protected constructor(source: Publisher<T>);
284
- /**
285
- * Default demand issued in the auto-request onSubscribe when using the
286
- * convenience subscribe() overloads (no explicit Subscriber provided).
287
- * Mono overrides this to 1; Flux overrides it to Number.MAX_SAFE_INTEGER.
288
- */
289
- protected abstract defaultDemand(): number;
290
- /**
291
- * Subscribe with a full Subscriber (existing contract — full demand control).
292
- */
293
- subscribe(subscriber: Subscriber<T>): Subscription;
294
- /**
295
- * Convenience overload — any combination of callbacks may be omitted.
296
- * An auto-request of `defaultDemand()` is issued on subscribe so items
297
- * start flowing immediately without a manual request() call.
298
- *
299
- * If `onError` is not provided, unhandled errors are re-thrown so they
300
- * surface as uncaught exceptions rather than being silently swallowed.
301
- *
302
- * @example
303
- * // Mono — requests 1 automatically
304
- * Mono.just(42).subscribe(v => console.log(v));
305
- *
306
- * // Flux — requests unbounded automatically
307
- * Flux.range(0, 5).subscribe(v => console.log(v), err => console.error(err));
308
- */
309
- subscribe(onNext?: (value: T) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription;
310
- /**
311
- * Wraps a publisher in the concrete subclass type.
312
- * Called internally by every operator that preserves T.
313
- */
314
- protected abstract wrapSource(source: Publisher<T>): Self;
315
- /**
316
- * Falls back to `alternative` if this source completes without emitting any items.
317
- *
318
- * If the source emits at least one item, `alternative` is never subscribed to.
319
- * If the source errors, the error is forwarded and `alternative` is not subscribed to.
320
- *
321
- * @param alternative - Publisher to subscribe to if the source is empty.
322
- * @returns A publisher that uses `alternative` when the source is empty.
323
- */
324
- switchIfEmpty(alternative: Publisher<T>): Self;
325
- /**
326
- * Substitutes the error signal with items from `replacement`.
327
- *
328
- * When the source signals `onError`, `replacement` is subscribed to and its items are
329
- * forwarded downstream as if they came from the original source.
330
- * If `replacement` itself errors, that error is forwarded.
331
- *
332
- * @param replacement - Publisher whose items replace the error.
333
- * @returns A publisher that recovers from errors by switching to `replacement`.
334
- */
335
- onErrorReturn(replacement: Publisher<T>): Self;
336
- /**
337
- * Handles errors selectively: if `predicate(error)` returns `true`, the error is
338
- * swallowed and the stream completes normally; otherwise the error is forwarded.
339
- *
340
- * @param predicate - Receives the error and returns `true` to suppress it.
341
- * @returns A publisher that converts matching errors into normal completions.
342
- */
343
- onErrorContinue(predicate: (error: Error) => boolean): Self;
344
- /**
345
- * Executes a side-effect `fn` on the **first** item emitted by the source.
346
- *
347
- * Subsequent items pass through unchanged. Any exception thrown by `fn` is silently swallowed.
348
- *
349
- * @param fn - Side-effect to run on the very first item.
350
- * @returns A publisher with the side effect attached to the first item.
351
- */
352
- doFirst(fn: () => void): Self;
353
- /**
354
- * Executes a side-effect `fn` for every item emitted by the source, before
355
- * forwarding the item downstream.
356
- *
357
- * Any exception thrown by `fn` is silently swallowed; the item is still forwarded.
358
- *
359
- * @param fn - Side-effect called for each item.
360
- * @returns A publisher with the side effect attached to each item.
361
- */
362
- doOnNext(fn: (value: T) => void): Self;
363
- /**
364
- * Executes a side-effect `fn` when the source signals an error, before
365
- * forwarding the error downstream.
366
- *
367
- * Any exception thrown by `fn` is silently swallowed; the original error is still forwarded.
368
- *
369
- * @param fn - Side-effect called with the error.
370
- * @returns A publisher with the side effect attached to the error signal.
371
- */
372
- doOnError(fn: (error: Error) => void): Self;
373
- /**
374
- * Executes a side-effect `fn` when the source calls `onSubscribe`, passing the
375
- * resulting {@link Subscription} to the callback.
376
- *
377
- * Any exception thrown by `fn` is silently swallowed.
378
- *
379
- * @param fn - Side-effect called with the subscription object.
380
- * @returns A publisher with the side effect attached to the subscribe event.
381
- */
382
- doOnSubscribe(fn: (subscription: Subscription) => void): Self;
383
- /**
384
- * Shifts item delivery to the given `scheduler`.
385
- *
386
- * Each `onNext`, `onError`, and `onComplete` callback is scheduled on `scheduler`
387
- * instead of being called inline. The source is still subscribed to on the
388
- * calling thread; only the *delivery* of signals is redirected.
389
- *
390
- * @param scheduler - The scheduler on which downstream signals are delivered.
391
- * @returns A publisher that delivers signals on the given scheduler.
392
- */
393
- publishOn(scheduler: Scheduler): Self;
394
- /**
395
- * Falls back to a publisher produced by `fn` when the source signals an error.
396
- *
397
- * Unlike {@link onErrorReturn} (which takes a static replacement), this operator
398
- * calls `fn` with the actual error, allowing dynamic recovery based on the error type.
399
- *
400
- * @param fn - Called with the error; returns the replacement publisher.
401
- * @returns A publisher that recovers from errors dynamically.
402
- *
403
- * @example
404
- * ```typescript
405
- * Flux.error(new Error('not found'))
406
- * .onErrorResume(e => e.message === 'not found' ? Flux.just('default') : Flux.error(e))
407
- * .subscribe(v => console.log(v)); // 'default'
408
- * ```
409
- */
410
- onErrorResume(fn: (error: Error) => Publisher<T>): Self;
411
- /**
412
- * Transforms the error signal using `fn` before forwarding it downstream.
413
- *
414
- * Useful for converting low-level errors into domain-specific error types.
415
- *
416
- * @param fn - Receives the original error and returns a replacement error.
417
- * @returns A publisher that transforms errors before propagating them.
418
- *
419
- * @example
420
- * ```typescript
421
- * Flux.error(new Error('HTTP 404'))
422
- * .onErrorMap(e => new Error(`NotFound: ${e.message}`))
423
- * .subscribe(null, e => console.error(e.message)); // NotFound: HTTP 404
424
- * ```
425
- */
426
- onErrorMap(fn: (error: Error) => Error): Self;
427
- /**
428
- * Emits a `TimeoutError` (or switches to `fallback`) if no item is received
429
- * within `ms` milliseconds of the previous item (or of subscription).
430
- *
431
- * The timer resets on each received item, so it measures **inter-item** idle time.
432
- *
433
- * @param ms - Timeout duration in milliseconds.
434
- * @param fallback - Optional publisher to switch to on timeout instead of erroring.
435
- * @returns A publisher that errors or falls back when no item arrives in time.
436
- *
437
- * @example
438
- * ```typescript
439
- * Flux.never<number>()
440
- * .timeout(100)
441
- * .subscribe(null, e => console.error(e.message)); // TimeoutError after 100ms
442
- * ```
443
- */
444
- timeout(ms: number, fallback?: Publisher<T>): Self;
445
- /**
446
- * Delays the subscription to the upstream source by `ms` milliseconds.
447
- *
448
- * `onSubscribe` is delivered immediately with a proxy `Subscription`.
449
- * Any `request(n)` calls before the delay elapses are accumulated and
450
- * forwarded once the actual subscription starts.
451
- *
452
- * @param ms - Delay in milliseconds before subscribing to the source.
453
- * @returns A publisher whose upstream subscription is deferred.
454
- */
455
- delaySubscription(ms: number): Self;
456
- /**
457
- * Logs each reactive signal to the console for debugging.
458
- *
459
- * Prints `onSubscribe`, `request(n)`, `onNext(value)`, `onError`, `onComplete`,
460
- * and `cancel` with an optional label prefix.
461
- *
462
- * @param label - Optional label prepended to each log line (default: `'reactor'`).
463
- * @returns A publisher with logging side effects attached.
464
- *
465
- * @example
466
- * ```typescript
467
- * Flux.just(1, 2).log('source').subscribe(v => console.log(v));
468
- * // [source] onSubscribe
469
- * // [source] request(9007199254740991)
470
- * // [source] onNext(1)
471
- * // ...
472
- * ```
473
- */
474
- log(label?: string): Self;
475
- /**
476
- * Executes a side-effect `fn` whenever the downstream subscriber issues a `request(n)`.
477
- *
478
- * Useful for debugging backpressure — see exactly how much demand is flowing upstream.
479
- * Any exception thrown by `fn` is silently swallowed.
480
- *
481
- * @param fn - Called with the requested count `n`.
482
- * @returns A publisher with the side effect attached to the request signal.
483
- */
484
- doOnRequest(fn: (n: number) => void): Self;
485
- /**
486
- * Executes a side-effect `fn` for every reactive signal (next, error, complete).
487
- *
488
- * The {@link Signal} discriminated union lets you inspect the kind and payload
489
- * of each event in a single callback.
490
- *
491
- * @param fn - Called for every signal with a {@link Signal} wrapper.
492
- * @returns A publisher with the side effect attached to all signals.
493
- *
494
- * @example
495
- * ```typescript
496
- * Flux.just(1, 2)
497
- * .doOnEach(s => { if (s.kind === 'next') console.log('item:', s.value); })
498
- * .subscribe();
499
- * ```
500
- */
501
- doOnEach(fn: (signal: Signal<T>) => void): Self;
502
- /**
503
- * Shifts the *subscription* (and source execution) to the given `scheduler`.
504
- *
505
- * The actual call to `this.source.subscribe(...)` is deferred and run on `scheduler`.
506
- * Downstream `onSubscribe` is delivered immediately on the calling thread with a proxy
507
- * `Subscription` that buffers `request(n)` calls until the source subscription is ready.
508
- *
509
- * Use this for cold sources that do their work synchronously on subscribe — it moves
510
- * that work to a different thread/context.
511
- *
512
- * @param scheduler - The scheduler on which the source is subscribed to and runs.
513
- * @returns A publisher whose source execution runs on the given scheduler.
514
- */
515
- subscribeOn(scheduler: Scheduler): Self;
516
- }
517
-
518
- /**
519
- * Backpressure-aware push interface handed to the generator function of {@link Flux.create}.
520
- *
521
- * Extends {@link Sink} with demand tracking and lifecycle hooks so the producer
522
- * can react to downstream request signals and cancellation. The generator may call
523
- * `next`, `error`, and `complete` freely from any context (event listener, timer,
524
- * callback). Items pushed when downstream demand is zero are buffered and delivered
525
- * as soon as demand becomes available.
526
- *
527
- * @typeParam T - The type of items to push.
528
- */
529
- interface FluxSink<T> extends Sink<T> {
530
- /**
531
- * Push the next value. Buffered if downstream has no outstanding demand.
532
- * No-op after `complete()` or `error()` have been called.
533
- */
534
- next(value: T): void;
535
- /**
536
- * Terminate the stream with an error.
537
- * No-op if the sink has already terminated.
538
- */
539
- error(error: Error): void;
540
- /**
541
- * Complete the stream normally.
542
- * No-op if the sink has already terminated.
543
- */
544
- complete(): void;
545
- /**
546
- * The current downstream demand (number of items the subscriber has requested
547
- * but not yet received). Useful for push-pull hybrid sources.
548
- */
549
- readonly requested: number;
550
- /**
551
- * Register a callback that is called each time downstream requests more items.
552
- * Multiple callbacks may be registered; they are all called in registration order.
553
- * @param fn - Called with the additional demand count.
554
- * @returns `this` for chaining.
555
- */
556
- onRequest(fn: (n: number) => void): FluxSink<T>;
557
- /**
558
- * Register a callback that is called when downstream cancels (unsubscribes).
559
- * @param fn - Cancellation handler.
560
- * @returns `this` for chaining.
561
- */
562
- onCancel(fn: () => void): FluxSink<T>;
563
- /**
564
- * Register a callback that is called when the sink is disposed —
565
- * either by cancellation or terminal signal.
566
- * @param fn - Disposal handler.
567
- * @returns `this` for chaining.
568
- */
569
- onDispose(fn: () => void): FluxSink<T>;
570
- }
571
-
572
- /**
573
- * Minimal interface compatible with the browser `WebSocket` API and the `ws` npm package.
574
- *
575
- * Any object that exposes `onmessage`, `onerror`, `onclose`, and `close()` satisfies
576
- * this interface and can be passed to {@link Flux.fromWebSocket}.
577
- *
578
- * @typeParam T - The type of `event.data` received in each message.
579
- */
580
- interface WebSocketLike<T = unknown> {
581
- /** Assigned when a message arrives; `event.data` carries the payload. */
582
- onmessage: ((event: {
583
- data: T;
584
- }) => void) | null;
585
- /** Assigned when a transport-level error occurs. */
586
- onerror: ((event: unknown) => void) | null;
587
- /** Assigned when the connection is closed. */
588
- onclose: ((event: {
589
- code: number;
590
- reason: string | Buffer;
591
- }) => void) | null;
592
- /** Close the connection, optionally with a status code and reason. */
593
- close(code?: number, reason?: string | Buffer): void;
594
- /** Current connection state (0 = CONNECTING, 1 = OPEN, 2 = CLOSING, 3 = CLOSED). */
595
- readonly readyState: number;
596
- }
597
- /**
598
- * Minimal DOM-style event target interface (`addEventListener` / `removeEventListener`).
599
- * Satisfied by browser `EventTarget`, `HTMLElement`, `window`, `document`, etc.
600
- *
601
- * @typeParam T - The event type emitted by the target.
602
- */
603
- interface DOMEventTargetLike<T = Event> {
604
- addEventListener(type: string, listener: (event: T) => void): void;
605
- removeEventListener(type: string, listener: (event: T) => void): void;
606
- }
607
- /**
608
- * Minimal Node.js-style event emitter interface (`on` / `off`).
609
- * Satisfied by Node.js `EventEmitter` and any object with the same shape.
610
- *
611
- * @typeParam T - The event data type emitted by the emitter.
612
- */
613
- interface NodeEventEmitterLike<T = unknown> {
614
- on(event: string | symbol, listener: (data: T) => void): void;
615
- off(event: string | symbol, listener: (data: T) => void): void;
616
- }
617
- /**
618
- * Union of {@link DOMEventTargetLike} and {@link NodeEventEmitterLike}.
619
- * Accepted by {@link Flux.fromEvent}.
620
- */
621
- type EventSourceLike<T = unknown> = DOMEventTargetLike<T> | NodeEventEmitterLike<T>;
622
- /**
623
- * A cold publisher of 0 to N items with full backpressure support.
624
- *
625
- * Items flow only when the downstream {@link Subscription} issues `request(n)`.
626
- * The convenience `subscribe(onNext, onError, onComplete)` overloads
627
- * automatically request `Number.MAX_SAFE_INTEGER` so items start arriving
628
- * without extra ceremony.
629
- *
630
- * Each `subscribe()` call creates an **independent** run of the pipeline
631
- * ("cold" semantics). Use {@link Flux.cache} or {@link Sinks} to share a
632
- * single run across multiple subscribers.
633
- *
634
- * @typeParam T - The type of items emitted by this Flux.
635
- *
636
- * @example
637
- * ```typescript
638
- * Flux.just(1, 2, 3)
639
- * .map(n => n * 2)
640
- * .filter(n => n > 2)
641
- * .subscribe(v => console.log(v));
642
- * // 4 6
643
- * ```
644
- */
645
- declare class Flux<T> extends AbstractPipePublisher<T, Flux<T>> implements PipePublisher<T> {
646
- protected constructor(source: Publisher<T>);
647
- protected defaultDemand(): number;
648
- protected wrapSource(source: Publisher<T>): Flux<T>;
649
- /**
650
- * Wraps an existing {@link Publisher} as a `Flux`.
651
- *
652
- * @param publisher - Any `Publisher<T>` to adapt.
653
- * @returns A `Flux<T>` backed by the given publisher.
654
- */
655
- static from<T>(publisher: Publisher<T>): Flux<T>;
656
- /**
657
- * Creates a `Flux` from a generator function that pushes values imperatively.
658
- *
659
- * The generator receives a {@link Sink} and may call `sink.next(v)` any number
660
- * of times, then `sink.complete()` or `sink.error(e)`. Delivery is
661
- * **backpressure-aware**: items pushed when demand is zero are buffered and
662
- * delivered as downstream issues `request(n)`.
663
- *
664
- * Rule 1.3 is respected — `onSubscribe` is delivered to the subscriber
665
- * **before** the generator runs.
666
- *
667
- * @param generator - Function that pushes items via the provided `Sink<T>`.
668
- * @returns A cold `Flux<T>`.
669
- *
670
- * @example
671
- * ```typescript
672
- * Flux.generate<number>(sink => {
673
- * sink.next(1);
674
- * sink.next(2);
675
- * sink.complete();
676
- * }).subscribe(v => console.log(v)); // 1 2
677
- * ```
678
- */
679
- static generate<T>(generator: (sink: Sink<T>) => void): Flux<T>;
680
- /**
681
- * Creates a `Flux` that emits every element of an `Iterable` in order, then completes.
682
- *
683
- * @param iterable - Any `Iterable<T>` (Array, Set, Map, generator, etc.).
684
- * @returns A cold `Flux<T>`.
685
- *
686
- * @example
687
- * ```typescript
688
- * Flux.fromIterable(['a', 'b', 'c']).subscribe(v => console.log(v));
689
- * // a b c
690
- * ```
691
- */
692
- static fromIterable<T>(iterable: Iterable<T>): Flux<T>;
693
- /**
694
- * Creates a `Flux` that emits `count` sequential integers starting at `start`.
695
- *
696
- * @param start - First integer to emit.
697
- * @param count - Number of integers to emit.
698
- * @returns A cold `Flux<number>` emitting `[start, start + count)`.
699
- *
700
- * @example
701
- * ```typescript
702
- * Flux.range(0, 5).subscribe(v => console.log(v)); // 0 1 2 3 4
703
- * ```
704
- */
705
- static range(start: number, count: number): Flux<number>;
706
- /**
707
- * Creates a `Flux` that completes immediately without emitting any items.
708
- *
709
- * @returns An empty, completed `Flux<T>`.
710
- */
711
- static empty<T = never>(): Flux<T>;
712
- /**
713
- * Lazily creates a new `Flux` per subscription by calling `factory`.
714
- *
715
- * Useful when the source depends on mutable state that should be captured
716
- * at subscribe time rather than at assembly time.
717
- *
718
- * @param factory - Called once per subscription to produce the actual `Flux<T>`.
719
- * @returns A lazy `Flux<T>`.
720
- */
721
- static defer<T>(factory: () => Flux<T>): Flux<T>;
722
- /**
723
- * Creates a `Flux` that emits the provided items in order, then completes.
724
- *
725
- * @param items - Zero or more items to emit.
726
- * @returns A cold `Flux<T>`.
727
- *
728
- * @example
729
- * ```typescript
730
- * Flux.just(1, 2, 3).subscribe(v => console.log(v)); // 1 2 3
731
- * ```
732
- */
733
- static just<T>(...items: T[]): Flux<T>;
734
- /**
735
- * Creates a `Flux` that signals `onError` immediately upon subscription.
736
- *
737
- * @param error - The error to signal.
738
- * @returns An errored `Flux<T>`.
739
- */
740
- static error<T = never>(error: Error): Flux<T>;
741
- /**
742
- * Creates a `Flux` that never emits any signal — no items, no error, no completion.
743
- * Useful as a placeholder or to represent an infinite, empty stream.
744
- *
745
- * @returns A `Flux<T>` that stays subscribed forever.
746
- */
747
- static never<T = never>(): Flux<T>;
748
- /**
749
- * Creates a `Flux` from a generator function that **pushes** values imperatively
750
- * via a {@link FluxSink}.
751
- *
752
- * Unlike {@link Flux.generate} (which is request-pull), `create` is designed for
753
- * **push-based** sources (EventEmitter, WebSocket, DOM events, Node.js streams).
754
- * Items pushed when downstream demand is zero are **buffered** and delivered as demand
755
- * becomes available.
756
- *
757
- * Register `onRequest`, `onCancel`, and `onDispose` callbacks on the sink to respond
758
- * to downstream lifecycle events.
759
- *
760
- * @param emitter - Called once per subscription; receives a `FluxSink<T>` for pushing values.
761
- * @returns A cold `Flux<T>`.
762
- *
763
- * @example
764
- * ```typescript
765
- * const emitter = new EventEmitter();
766
- * const flux = Flux.create<string>(sink => {
767
- * emitter.on('data', v => sink.next(v));
768
- * emitter.on('end', () => sink.complete());
769
- * sink.onCancel(() => emitter.removeAllListeners());
770
- * });
771
- * ```
772
- */
773
- static create<T>(emitter: (sink: FluxSink<T>) => void): Flux<T>;
774
- /**
775
- * Creates a `Flux` that acquires a resource, uses it to build a source publisher,
776
- * and guarantees the resource is cleaned up when the stream terminates or is cancelled.
777
- *
778
- * The cleanup runs after `onComplete`, `onError`, or `unsubscribe()` — whichever
779
- * happens first.
780
- *
781
- * @param resourceSupplier - Called once per subscription to acquire the resource.
782
- * @param sourceFactory - Builds the source publisher from the resource.
783
- * @param cleanup - Called with the resource after the stream terminates.
784
- * @returns A `Flux<T>` with guaranteed resource cleanup.
785
- *
786
- * @example
787
- * ```typescript
788
- * Flux.using(
789
- * () => openFile('data.txt'),
790
- * file => Flux.fromIterable(file.readLines()),
791
- * file => file.close()
792
- * ).subscribe(line => console.log(line));
793
- * ```
794
- */
795
- static using<T, R>(resourceSupplier: () => R, sourceFactory: (resource: R) => Publisher<T>, cleanup: (resource: R) => void): Flux<T>;
796
- /**
797
- * Creates a `Flux<T>` that emits each message received on a `WebSocket`.
798
- *
799
- * - Each message's `data` is emitted as the next item.
800
- * - The stream **completes** when the socket is closed (any close code).
801
- * - A transport-level error event terminates the stream with an `Error`.
802
- * - **Unsubscribing** closes the socket gracefully (sends a normal-closure frame).
803
- *
804
- * Compatible with the browser `WebSocket` API and the `ws` npm package. Any object
805
- * satisfying the {@link WebSocketLike} interface can be passed.
806
- *
807
- * @param ws - An open (or opening) WebSocket instance.
808
- * @returns A `Flux<T>` backed by the WebSocket message stream.
809
- *
810
- * @example
811
- * ```typescript
812
- * // Browser
813
- * Flux.fromWebSocket<string>(new WebSocket('wss://example.com/chat'))
814
- * .map(msg => JSON.parse(msg))
815
- * .subscribe(msg => console.log(msg));
816
- *
817
- * // Node.js (ws package)
818
- * import WebSocket from 'ws';
819
- * Flux.fromWebSocket<Buffer>(new WebSocket('ws://localhost:8080'))
820
- * .map(buf => buf.toString())
821
- * .subscribe(text => console.log(text));
822
- * ```
823
- */
824
- static fromWebSocket<T = unknown>(ws: WebSocketLike<T>): Flux<T>;
825
- /**
826
- * Creates an infinite `Flux<T>` that emits every event of type `eventName` fired on
827
- * `target`. The stream never completes on its own — call `unsubscribe()` or chain a
828
- * limiting operator (e.g. `.take(n)`, `.takeUntilOther(stop$)`) to terminate it.
829
- *
830
- * Works with:
831
- * - **DOM targets** (`EventTarget`: `HTMLElement`, `window`, `document`, …) — uses
832
- * `addEventListener` / `removeEventListener`.
833
- * - **Node.js emitters** (any object with `on` / `off`) — uses those methods directly.
834
- *
835
- * Events fired while downstream has no demand are **buffered** (via {@link Flux.create})
836
- * and delivered once demand is available.
837
- *
838
- * @param target - A DOM `EventTarget` or Node.js-style event emitter.
839
- * @param eventName - The event name / type to listen for.
840
- * @returns An infinite cold `Flux<T>` of matching events.
841
- *
842
- * @example
843
- * ```typescript
844
- * // Browser — click events on a button
845
- * Flux.fromEvent<MouseEvent>(document.getElementById('btn')!, 'click')
846
- * .map(e => ({ x: e.clientX, y: e.clientY }))
847
- * .subscribe(pos => console.log(pos));
848
- *
849
- * // Node.js EventEmitter
850
- * import { EventEmitter } from 'events';
851
- * const emitter = new EventEmitter();
852
- * Flux.fromEvent<string>(emitter, 'data')
853
- * .take(5)
854
- * .subscribe(v => console.log(v));
855
- * ```
856
- */
857
- static fromEvent<T = Event>(target: EventSourceLike<T>, eventName: string): Flux<T>;
858
- /**
859
- * Merges N publishers by subscribing to all of them concurrently and interleaving
860
- * their items as they arrive.
861
- *
862
- * The stream completes when **all** sources complete.
863
- * Any error from any source terminates the merged stream immediately.
864
- *
865
- * @param sources - Publishers to merge.
866
- * @returns A `Flux<T>` that emits items from all sources concurrently.
867
- *
868
- * @example
869
- * ```typescript
870
- * Flux.merge(Flux.just(1, 2), Flux.just(3, 4)).subscribe(v => console.log(v));
871
- * // 1 2 3 4 (order may vary for async sources)
872
- * ```
873
- */
874
- static merge<T>(...sources: Publisher<T>[]): Flux<T>;
875
- /**
876
- * Subscribes to all `sources` concurrently and emits the **first value** produced
877
- * by any of them. All other subscriptions are cancelled immediately after the winner emits.
878
- *
879
- * If all sources complete without emitting a value, the result completes empty.
880
- * Errors from non-winning sources are ignored once a winner is found.
881
- *
882
- * @param sources - Publishers to race.
883
- * @returns A `Flux<T>` that emits the first value from any source.
884
- *
885
- * @example
886
- * ```typescript
887
- * // Take whichever request responds first
888
- * Flux.firstWithValue(fetchFromCDN(), fetchFromOrigin())
889
- * .subscribe(data => console.log(data));
890
- * ```
891
- */
892
- static firstWithValue<T>(...sources: Publisher<T>[]): Flux<T>;
893
- /**
894
- * Emits an ever-incrementing counter (0, 1, 2, …) at a fixed `ms` rate.
895
- *
896
- * Items are **dropped** when downstream has no outstanding demand (rather than
897
- * buffered), matching Reactor's `Flux.interval` drop-on-overflow behaviour.
898
- * The stream never completes on its own — cancel the subscription to stop it.
899
- *
900
- * @param ms - Interval duration in milliseconds.
901
- * @returns An infinite `Flux<number>`.
902
- *
903
- * @example
904
- * ```typescript
905
- * Flux.interval(1000).take(3).subscribe(n => console.log(n)); // 0 1 2
906
- * ```
907
- */
908
- static interval(ms: number): Flux<number>;
909
- /**
910
- * Combines items from 2 sources positionally via `combiner`.
911
- * Emits one combined value for each position; stops when the shorter source exhausts.
912
- */
913
- static zip<A, B, R>(sources: [Publisher<A>, Publisher<B>], combiner: (a: A, b: B) => R): Flux<R>;
914
- /**
915
- * Combines items from 3 sources positionally via `combiner`.
916
- */
917
- static zip<A, B, C, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>], combiner: (a: A, b: B, c: C) => R): Flux<R>;
918
- /**
919
- * Combines items from 4 sources positionally via `combiner`.
920
- */
921
- static zip<A, B, C, D, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>, Publisher<D>], combiner: (a: A, b: B, c: C, d: D) => R): Flux<R>;
922
- /**
923
- * General N-source positional zip.
924
- *
925
- * Subscribes to each source concurrently, using a prefetch of 1 per source.
926
- * Once every source has provided one item for a given position, `combiner` is
927
- * called with those items and the result is emitted downstream. The stream
928
- * completes when any source completes and has no buffered items left.
929
- *
930
- * @param sources - Publishers to zip.
931
- * @param combiner - Combines one item from each source at the same position.
932
- * @returns A `Flux<R>` of combined values.
933
- *
934
- * @example
935
- * ```typescript
936
- * Flux.zip([Flux.just(1, 2), Flux.just('a', 'b')], (n, s) => `${n}${s}`)
937
- * .subscribe(v => console.log(v)); // '1a' '2b'
938
- * ```
939
- */
940
- static zip<T, R>(sources: Publisher<T>[], combiner: (...args: T[]) => R): Flux<R>;
941
- /**
942
- * Combines the **latest** value from each source whenever any source emits.
943
- *
944
- * Does not emit until all sources have produced at least one value.
945
- * Continues emitting with each new item from any source, using the latest values
946
- * from all others. Sources run at unbounded speed; downstream demand controls delivery.
947
- *
948
- * @param sources - Publishers to combine.
949
- * @param combiner - Called with the latest value from each source.
950
- * @returns A `Flux<R>` of combined values.
951
- *
952
- * @example
953
- * ```typescript
954
- * Flux.combineLatest([Flux.just(1, 2), Flux.just('a', 'b')], (n, s) => `${n}${s}`)
955
- * .subscribe(v => console.log(v)); // '1a' '2a' '2b' (order depends on timing)
956
- * ```
957
- */
958
- static combineLatest<A, B, R>(sources: [Publisher<A>, Publisher<B>], combiner: (a: A, b: B) => R): Flux<R>;
959
- static combineLatest<A, B, C, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>], combiner: (a: A, b: B, c: C) => R): Flux<R>;
960
- static combineLatest<A, B, C, D, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>, Publisher<D>], combiner: (a: A, b: B, c: C, d: D) => R): Flux<R>;
961
- static combineLatest<T, R>(sources: Publisher<T>[], combiner: (...args: T[]) => R): Flux<R>;
962
- /**
963
- * Transforms each item using `fn`, producing a `Flux<R>`.
964
- *
965
- * If `fn` throws, the exception is forwarded to `onError` and the stream terminates.
966
- *
967
- * @param fn - Mapping function applied to every item.
968
- * @returns A new `Flux<R>`.
969
- *
970
- * @example
971
- * ```typescript
972
- * Flux.just(1, 2, 3).map(n => n * 10).subscribe(v => console.log(v));
973
- * // 10 20 30
974
- * ```
975
- */
976
- map<R>(fn: (value: T) => R): Flux<R>;
977
- /**
978
- * Transforms each item with `fn`, silently discarding `null`/`undefined` results.
979
- *
980
- * When an item is discarded, upstream demand is replenished by 1 so the
981
- * downstream demand accounting stays correct.
982
- *
983
- * @param fn - Mapping function; returning `null` or `undefined` skips the item.
984
- * @returns A `Flux<NonNullable<R>>` with nulls filtered out.
985
- *
986
- * @example
987
- * ```typescript
988
- * Flux.just('hello', '', 'world')
989
- * .mapNotNull(s => s.length > 0 ? s : null)
990
- * .subscribe(v => console.log(v));
991
- * // hello world
992
- * ```
993
- */
994
- mapNotNull<R>(fn: (value: T) => R | null | undefined): Flux<NonNullable<R>>;
995
- /**
996
- * Fine-grained per-item transform: the `handler` receives each item together with
997
- * a {@link Sink} and may emit **0 or 1** result items.
998
- *
999
- * - Calling `sink.next(r)` once emits `r` downstream.
1000
- * - Calling `sink.next(r)` more than once is silently ignored (0-or-1 semantics).
1001
- * - Calling `sink.complete()` or `sink.error(e)` terminates the stream early.
1002
- * - If the handler emits nothing (0 items), upstream demand is replenished by 1.
1003
- *
1004
- * This is the Flux equivalent of `reactor-core`'s `handle(BiConsumer<T, SynchronousSink<R>>)`.
1005
- *
1006
- * @param handler - Called for each upstream item with the item and an output `Sink<R>`.
1007
- * @returns A `Flux<R>`.
1008
- *
1009
- * @example
1010
- * ```typescript
1011
- * // Convert strings to numbers, skip non-numeric entries
1012
- * Flux.just('1', 'two', '3').handle<number>((s, sink) => {
1013
- * const n = parseInt(s);
1014
- * if (!isNaN(n)) sink.next(n);
1015
- * }).subscribe(v => console.log(v));
1016
- * // 1 3
1017
- * ```
1018
- */
1019
- handle<R>(handler: (value: T, sink: Sink<R>) => void): Flux<R>;
1020
- /**
1021
- * Maps each item to an inner publisher and merges all inner publishers concurrently
1022
- * into a single `Flux<R>` (**merge** semantics).
1023
- *
1024
- * Inner publishers are subscribed to as soon as their corresponding outer item arrives.
1025
- * Items from different inner publishers can interleave. The resulting stream completes
1026
- * when the outer source completes **and** all inner publishers complete. Any error
1027
- * (from outer or any inner) immediately terminates the stream.
1028
- *
1029
- * @param fn - Maps each item to a `Flux<R>`, `Mono<R>`, or any `Publisher<R>`.
1030
- * @returns A merged `Flux<R>`.
1031
- *
1032
- * @example
1033
- * ```typescript
1034
- * Flux.just(1, 2, 3)
1035
- * .flatMap(n => Mono.just(n * 10))
1036
- * .subscribe(v => console.log(v));
1037
- * // 10 20 30 (order may vary with async inner publishers)
1038
- * ```
1039
- */
1040
- flatMap<R>(fn: (value: T) => Flux<R>): Flux<R>;
1041
- flatMap<R>(fn: (value: T) => Mono<R>): Flux<R>;
1042
- flatMap<R>(fn: (value: T) => Publisher<R>): Flux<R>;
1043
- /**
1044
- * Maps each item to an inner publisher and subscribes to them **sequentially**,
1045
- * preserving order (**concat** semantics).
1046
- *
1047
- * The next inner publisher is subscribed to only after the previous one completes.
1048
- * This guarantees item ordering but has no concurrency.
1049
- *
1050
- * @param fn - Maps each item to a `Flux<R>`, `Mono<R>`, or any `Publisher<R>`.
1051
- * @returns An ordered, sequential `Flux<R>`.
1052
- *
1053
- * @example
1054
- * ```typescript
1055
- * Flux.just(1, 2, 3)
1056
- * .concatMap(n => Mono.just(`item-${n}`))
1057
- * .subscribe(v => console.log(v));
1058
- * // item-1 item-2 item-3
1059
- * ```
1060
- */
1061
- concatMap<R>(fn: (value: T) => Flux<R>): Flux<R>;
1062
- concatMap<R>(fn: (value: T) => Mono<R>): Flux<R>;
1063
- concatMap<R>(fn: (value: T) => Publisher<R>): Flux<R>;
1064
- /**
1065
- * Maps each item to an inner publisher, **cancelling** the previous inner subscription
1066
- * whenever a new outer item arrives (**switch** semantics).
1067
- *
1068
- * Only the most recently started inner publisher is active at any point. This is
1069
- * useful for patterns like "search as you type" where stale results should be
1070
- * discarded when a newer request supersedes them.
1071
- *
1072
- * @param fn - Maps each item to a `Flux<R>`, `Mono<R>`, or any `Publisher<R>`.
1073
- * @returns A `Flux<R>` that tracks only the latest inner publisher.
1074
- */
1075
- switchMap<R>(fn: (value: T) => Flux<R>): Flux<R>;
1076
- switchMap<R>(fn: (value: T) => Mono<R>): Flux<R>;
1077
- switchMap<R>(fn: (value: T) => Publisher<R>): Flux<R>;
1078
- /**
1079
- * Passes only items for which `predicate` returns `true`.
1080
- *
1081
- * Each dropped item replenishes upstream demand by 1 to keep the total
1082
- * outstanding demand accurate.
1083
- *
1084
- * @param predicate - Synchronous test applied to each item.
1085
- * @returns A filtered `Flux<T>`.
1086
- *
1087
- * @example
1088
- * ```typescript
1089
- * Flux.just(1, 2, 3, 4).filter(n => n % 2 === 0).subscribe(v => console.log(v));
1090
- * // 2 4
1091
- * ```
1092
- */
1093
- filter(predicate: (value: T) => boolean): Flux<T>;
1094
- /**
1095
- * Asynchronous filter: for each item, subscribes to `predicate(item)` and forwards
1096
- * the item downstream only if the predicate publisher emits `true`.
1097
- *
1098
- * Implemented via {@link concatMap} — predicates run sequentially.
1099
- *
1100
- * @param predicate - Returns a `Publisher<boolean>` for each item.
1101
- * @returns A filtered `Flux<T>`.
1102
- */
1103
- filterWhen(predicate: (value: T) => Publisher<boolean>): Flux<T>;
1104
- /**
1105
- * Unsafe type cast — changes the declared element type to `R` without any
1106
- * runtime conversion. Use only when you are certain the actual runtime
1107
- * type is compatible.
1108
- *
1109
- * @typeParam R - The target element type.
1110
- * @returns This `Flux` re-typed as `Flux<R>`.
1111
- */
1112
- cast<R>(): Flux<R>;
1113
- /**
1114
- * Emits at most `n` items, then cancels the upstream subscription and completes.
1115
- *
1116
- * If `n ≤ 0`, returns an empty `Flux` immediately.
1117
- *
1118
- * @param n - Maximum number of items to emit.
1119
- * @returns A bounded `Flux<T>`.
1120
- */
1121
- take(n: number): Flux<T>;
1122
- /**
1123
- * Emits items while `predicate(item)` returns `true`.
1124
- * Completes (and cancels upstream) on the first item for which it returns `false`.
1125
- *
1126
- * @param predicate - Tested synchronously for each item.
1127
- * @returns A `Flux<T>` that stops on the first `false`.
1128
- */
1129
- takeWhile(predicate: (value: T) => boolean): Flux<T>;
1130
- /**
1131
- * Forwards items from this `Flux` until `trigger` emits its first item (or completes),
1132
- * then cancels the source and completes downstream.
1133
- *
1134
- * If `trigger` signals an error, that error is forwarded to the subscriber.
1135
- *
1136
- * @param trigger - A `Publisher` whose first emission ends this stream.
1137
- * @returns A `Flux<T>` that stops when the trigger fires.
1138
- */
1139
- takeUntilOther(trigger: Publisher<unknown>): Flux<T>;
1140
- /** Emit defaultValue if source completes without emitting any item. */
1141
- /**
1142
- * Emits `value` if the source completes without having emitted any items,
1143
- * then completes. If the source does emit items, they pass through unchanged.
1144
- *
1145
- * @param value - Fallback item to emit when the source is empty.
1146
- * @returns A `Flux<T>` that is never empty.
1147
- */
1148
- defaultIfEmpty(value: T): Flux<T>;
1149
- /**
1150
- * Re-subscribes to the source on `onError`, up to `maxRetries` times.
1151
- *
1152
- * Accumulated downstream demand from previous attempts is preserved across retries.
1153
- * If the error persists after all retries are exhausted, it is forwarded to downstream.
1154
- *
1155
- * @param maxRetries - Maximum number of retry attempts (default: `Number.MAX_SAFE_INTEGER`).
1156
- * @returns A `Flux<T>` with automatic retry on error.
1157
- */
1158
- retry(maxRetries?: number): Flux<T>;
1159
- /**
1160
- * Emits a running accumulation of the stream.
1161
- *
1162
- * The first item is emitted as-is and becomes the initial accumulator.
1163
- * Each subsequent item is combined with the running accumulator using `reducer`,
1164
- * and the result is emitted downstream.
1165
- *
1166
- * @param reducer - Combines the running accumulator with the next item.
1167
- * @returns A `Flux<T>` of intermediate accumulation results.
1168
- *
1169
- * @example
1170
- * ```typescript
1171
- * Flux.just(1, 2, 3, 4).scan((acc, n) => acc + n).subscribe(v => console.log(v));
1172
- * // 1 3 6 10
1173
- * ```
1174
- */
1175
- scan(reducer: (acc: T, next: T) => T): Flux<T>;
1176
- /**
1177
- * Emits a running accumulation of the stream with an explicit seed value.
1178
- *
1179
- * `seedFactory` is called once per subscription to produce the initial accumulator.
1180
- * Each upstream item is folded into the accumulator and the intermediate result is
1181
- * emitted downstream.
1182
- *
1183
- * @param seedFactory - Called per subscription to produce the initial accumulator of type `A`.
1184
- * @param reducer - Combines the current accumulator with the next item.
1185
- * @returns A `Flux<A>` of intermediate accumulation results.
1186
- *
1187
- * @example
1188
- * ```typescript
1189
- * Flux.just(1, 2, 3).scanWith(() => 0, (acc, n) => acc + n).subscribe(v => console.log(v));
1190
- * // 1 3 6
1191
- * ```
1192
- */
1193
- scanWith<A>(seedFactory: () => A, reducer: (acc: A, next: T) => A): Flux<A>;
1194
- /**
1195
- * Pair-wise combines items from this `Flux` and `other` using `combiner`.
1196
- *
1197
- * Items are matched by position: the first item from each source is combined, then the second, etc.
1198
- * The stream completes when either source completes. If either source errors, the error is forwarded.
1199
- *
1200
- * @param other - The second publisher to zip with.
1201
- * @param combiner - Combines one item from each source into a result item.
1202
- * @returns A `Flux<V>` of combined pairs.
1203
- *
1204
- * @example
1205
- * ```typescript
1206
- * Flux.just(1, 2, 3)
1207
- * .zipWith(Flux.just('a', 'b', 'c'), (n, s) => `${n}${s}`)
1208
- * .subscribe(v => console.log(v));
1209
- * // 1a 2b 3c
1210
- * ```
1211
- */
1212
- zipWith<R, V>(other: Publisher<R>, combiner: (a: T, b: R) => V): Flux<V>;
1213
- /**
1214
- * Executes a side-effect function when the source completes normally.
1215
- *
1216
- * The function runs just before `onComplete` is forwarded to the downstream subscriber.
1217
- * Any exception thrown by `fn` is silently swallowed.
1218
- *
1219
- * @param fn - Side-effect to run on normal completion.
1220
- * @returns A `Flux<T>` with the side effect attached.
1221
- */
1222
- doOnComplete(fn: () => void): Flux<T>;
1223
- /**
1224
- * Executes a side-effect function when the source terminates — either normally (`onComplete`)
1225
- * or with an error (`onError`).
1226
- *
1227
- * The function runs before the terminal signal is forwarded downstream.
1228
- * Any exception thrown by `fn` is silently swallowed.
1229
- *
1230
- * @param fn - Side-effect to run on any terminal signal.
1231
- * @returns A `Flux<T>` with the side effect attached.
1232
- */
1233
- doOnTerminate(fn: () => void): Flux<T>;
1234
- /**
1235
- * Executes a side-effect function when the downstream subscriber cancels
1236
- * (calls `unsubscribe()`).
1237
- *
1238
- * Any exception thrown by `fn` is silently swallowed.
1239
- *
1240
- * @param fn - Side-effect to run on cancellation.
1241
- * @returns A `Flux<T>` with the side effect attached.
1242
- */
1243
- doOnCancel(fn: () => void): Flux<T>;
1244
- /**
1245
- * Executes a side-effect function after the stream ends for **any** reason —
1246
- * normal completion, error, or cancellation.
1247
- *
1248
- * Any exception thrown by `fn` is silently swallowed.
1249
- *
1250
- * @param fn - Side-effect to run after any terminal event or cancellation.
1251
- * @returns A `Flux<T>` with the side effect attached.
1252
- */
1253
- doFinally(fn: () => void): Flux<T>;
1254
- /**
1255
- * Low-level escape hatch for bridging imperative push-based sources.
1256
- *
1257
- * The `producer` receives three callbacks and must call them to drive the stream.
1258
- * `onRequest` and `onUnsubscribe` let the caller respond to downstream demand and
1259
- * cancellation respectively.
1260
- *
1261
- * @param producer - Callback that receives `(onNext, onError, onComplete)` and drives the stream.
1262
- * @param onRequest - Called when the downstream subscriber requests `n` more items.
1263
- * @param onUnsubscribe - Called when the downstream subscriber cancels.
1264
- * @returns A `Flux<R>` backed by the imperative producer.
1265
- */
1266
- pipe<R>(producer: (onNext: (value: R) => void, onError: (error: Error) => void, onComplete: () => void) => void, onRequest: (request: number) => void, onUnsubscribe: () => void): Flux<R>;
1267
- /**
1268
- * Returns the first item of this `Flux` as a `Mono`.
1269
- *
1270
- * If the source is empty, the resulting `Mono` completes without emitting a value.
1271
- * The source subscription is cancelled immediately after the first item is received.
1272
- *
1273
- * @returns A `Mono<T>` that emits the first item, or completes empty.
1274
- */
1275
- first(): Mono<T>;
1276
- /**
1277
- * Returns the last item of this `Flux` as a `Mono`.
1278
- *
1279
- * The source is fully consumed before the value is emitted.
1280
- * If the source is empty, the resulting `Mono` completes without emitting a value.
1281
- *
1282
- * @returns A `Mono<T>` that emits the last item, or completes empty.
1283
- */
1284
- last(): Mono<T>;
1285
- /**
1286
- * Counts all items emitted by this `Flux` and emits the total as a `Mono<number>`.
1287
- *
1288
- * The source is fully consumed before the count is emitted.
1289
- *
1290
- * @returns A `Mono<number>` emitting the number of items.
1291
- */
1292
- count(): Mono<number>;
1293
- /**
1294
- * Emits `true` if this `Flux` emits at least one item, `false` if it completes empty.
1295
- *
1296
- * The source subscription is cancelled as soon as the first item is observed.
1297
- *
1298
- * @returns A `Mono<boolean>`.
1299
- */
1300
- hasElements(): Mono<boolean>;
1301
- /**
1302
- * Emits `true` if any item matches `predicate`, `false` if none do.
1303
- *
1304
- * Short-circuits: cancels the source and emits `true` on the first matching item.
1305
- * If `predicate` throws, the error is forwarded to the subscriber.
1306
- *
1307
- * @param predicate - Test applied to each item.
1308
- * @returns A `Mono<boolean>`.
1309
- */
1310
- any(predicate: (value: T) => boolean): Mono<boolean>;
1311
- /**
1312
- * Emits `true` if every item matches `predicate`, `false` if any item does not.
1313
- *
1314
- * Short-circuits: cancels the source and emits `false` on the first non-matching item.
1315
- * If `predicate` throws, the error is forwarded to the subscriber.
1316
- *
1317
- * @param predicate - Test applied to each item.
1318
- * @returns A `Mono<boolean>`.
1319
- */
1320
- all(predicate: (value: T) => boolean): Mono<boolean>;
1321
- /**
1322
- * Emits `true` if no item matches `predicate`, `false` if any item does.
1323
- *
1324
- * This is the logical negation of {@link any}.
1325
- *
1326
- * @param predicate - Test applied to each item.
1327
- * @returns A `Mono<boolean>`.
1328
- */
1329
- none(predicate: (value: T) => boolean): Mono<boolean>;
1330
- /**
1331
- * Returns the item at zero-based `index` as a `Mono<T>`.
1332
- *
1333
- * If the source completes before reaching `index`, emits `defaultValue` if provided,
1334
- * otherwise completes empty.
1335
- *
1336
- * @param index - Zero-based position of the desired item.
1337
- * @param defaultValue - Optional fallback value emitted if the index is out of range.
1338
- * @returns A `Mono<T>`.
1339
- */
1340
- elementAt(index: number, defaultValue?: T): Mono<T>;
1341
- /**
1342
- * Collects all items into an array and emits the complete array as a `Mono<T[]>`.
1343
- *
1344
- * The source is fully consumed before the array is emitted.
1345
- *
1346
- * @returns A `Mono<T[]>` containing all emitted items.
1347
- */
1348
- collect(_force?: boolean): Mono<T[]>;
1349
- /**
1350
- * Alias for {@link collect}.
1351
- *
1352
- * @returns A `Mono<T[]>` containing all emitted items.
1353
- */
1354
- collectList(): Mono<T[]>;
1355
- /**
1356
- * Collects all items, sorts them, and re-emits them as a `Flux<T>`.
1357
- *
1358
- * Uses the native `Array.sort` algorithm. When no `comparator` is provided the
1359
- * default lexicographic sort order is used.
1360
- *
1361
- * @param comparator - Optional comparison function (same signature as `Array.sort`).
1362
- * @returns A `Flux<T>` that emits items in sorted order after the source completes.
1363
- */
1364
- sort(comparator?: (a: T, b: T) => number): Flux<T>;
1365
- /**
1366
- * Collects items into fixed-size arrays and emits each batch as a `T[]`.
1367
- *
1368
- * A batch is emitted as soon as it reaches `maxSize` items.
1369
- * The final (potentially partial) batch is emitted when the source completes.
1370
- *
1371
- * @param maxSize - Maximum number of items per batch.
1372
- * @returns A `Flux<T[]>` of item batches.
1373
- *
1374
- * @example
1375
- * ```typescript
1376
- * Flux.range(1, 5).buffer(2).subscribe(v => console.log(v));
1377
- * // [1, 2] [3, 4] [5]
1378
- * ```
1379
- */
1380
- buffer(maxSize: number): Flux<T[]>;
1381
- /**
1382
- * Caches all emitted items and replays them to each new subscriber.
1383
- *
1384
- * The source is subscribed to on the **first** downstream subscription (lazy connect).
1385
- * Subsequent subscribers receive a replay of all previously emitted items from the cache.
1386
- *
1387
- * @returns A cached, replayable `Flux<T>`.
1388
- */
1389
- cache(): Flux<T>;
1390
- /**
1391
- * Multicasts this `Flux` to all current subscribers using a refCounting strategy.
1392
- *
1393
- * The upstream is subscribed to when the **first** subscriber joins and cancelled
1394
- * when the **last** subscriber leaves. If a new subscriber arrives after all others
1395
- * have cancelled, a fresh upstream subscription is created.
1396
- *
1397
- * Items are delivered on a best-effort basis: a subscriber that has no outstanding
1398
- * demand when an item arrives simply misses that item (no buffering). Once the upstream
1399
- * terminates (complete or error), the terminal signal is replayed to any future subscriber.
1400
- *
1401
- * @returns A hot `Flux<T>` that shares a single upstream subscription.
1402
- *
1403
- * @example
1404
- * ```typescript
1405
- * const shared = Flux.interval(100).share();
1406
- * shared.subscribe(v => console.log('A', v));
1407
- * setTimeout(() => shared.subscribe(v => console.log('B', v)), 250);
1408
- * // A 0, A 1, A 2, B 2, A 3, B 3 ...
1409
- * ```
1410
- */
1411
- share(): Flux<T>;
1412
- /**
1413
- * Pairs each item with its zero-based index, emitting `[index, item]` tuples.
1414
- *
1415
- * @returns A `Flux<[number, T]>` where the first element is the zero-based index.
1416
- *
1417
- * @example
1418
- * ```typescript
1419
- * Flux.just('a', 'b', 'c').indexed().subscribe(([i, v]) => console.log(i, v));
1420
- * // 0 a 1 b 2 c
1421
- * ```
1422
- */
1423
- indexed(): Flux<[number, T]>;
1424
- /**
1425
- * Skips the first `n` items from the source, then forwards the rest.
1426
- *
1427
- * Skipped items replenish upstream demand so the overall demand accounting stays correct.
1428
- *
1429
- * @param n - Number of leading items to skip.
1430
- * @returns A `Flux<T>` without the first `n` items.
1431
- */
1432
- skip(n: number): Flux<T>;
1433
- /**
1434
- * Skips items while `predicate` returns `true`, then forwards all subsequent items
1435
- * regardless of the predicate.
1436
- *
1437
- * Skipped items replenish upstream demand. Once the predicate returns `false`, it is
1438
- * never evaluated again.
1439
- *
1440
- * @param predicate - Tested against each item until it returns `false`.
1441
- * @returns A `Flux<T>` that starts forwarding items after the first predicate failure.
1442
- */
1443
- skipWhile(predicate: (value: T) => boolean): Flux<T>;
1444
- /**
1445
- * Gates items from this `Flux` until `other` emits its first item.
1446
- *
1447
- * Items arriving before the gate opens are silently dropped (demand is replenished).
1448
- * If `other` signals an error, the error is forwarded to downstream.
1449
- *
1450
- * @param other - A `Publisher` whose first emission opens the gate.
1451
- * @returns A `Flux<T>` that starts forwarding items once `other` emits.
1452
- */
1453
- skipUntil(other: Publisher<unknown>): Flux<T>;
1454
- /**
1455
- * Filters out duplicate items, forwarding only items not seen before.
1456
- *
1457
- * Uses a `Set` with reference equality (`===`) to track seen values.
1458
- * Duplicates replenish upstream demand.
1459
- *
1460
- * @returns A `Flux<T>` with all duplicate items removed.
1461
- */
1462
- distinct(): Flux<T>;
1463
- /**
1464
- * Suppresses consecutive duplicate items.
1465
- *
1466
- * An item is forwarded only when it is different from the immediately preceding item
1467
- * as determined by `comparator`. The default comparator uses `!==`.
1468
- * Suppressed items replenish upstream demand.
1469
- *
1470
- * @param comparator - Returns `true` when two consecutive items are considered different
1471
- * (default: `(a, b) => a !== b`).
1472
- * @returns A `Flux<T>` without consecutive duplicates.
1473
- *
1474
- * @example
1475
- * ```typescript
1476
- * Flux.just(1, 1, 2, 2, 3).distinctUntilChanged().subscribe(v => console.log(v));
1477
- * // 1 2 3
1478
- * ```
1479
- */
1480
- distinctUntilChanged(comparator?: (a: T, b: T) => boolean): Flux<T>;
1481
- /**
1482
- * Delays the delivery of each item by `ms` milliseconds.
1483
- *
1484
- * Items are processed **one at a time**: the next item is requested from the source
1485
- * only after the previous delayed item has been delivered downstream. This guarantees
1486
- * items are spaced at least `ms` apart and that `onComplete` fires only after the last
1487
- * delayed item has been delivered.
1488
- *
1489
- * Errors are forwarded immediately without delay, cancelling any pending timer.
1490
- *
1491
- * @param ms - Delay in milliseconds between consecutive item deliveries.
1492
- * @returns A `Flux<T>` where each item is delayed by `ms` before being forwarded.
1493
- */
1494
- delayElements(ms: number): Flux<T>;
1495
- /**
1496
- * Appends `other` to this `Flux`, subscribing to `other` only after this source completes.
1497
- *
1498
- * Items from this source are emitted first, in order. Once this source completes,
1499
- * items from `other` are emitted. If either source errors, the error is forwarded
1500
- * and `other` is not subscribed to.
1501
- *
1502
- * @param other - The publisher to concatenate after this source.
1503
- * @returns A `Flux<T>` that emits items from both sources sequentially.
1504
- */
1505
- concatWith(other: Publisher<T>): Flux<T>;
1506
- /**
1507
- * Merges this `Flux` with `other`, subscribing to both concurrently.
1508
- *
1509
- * Items from both sources are interleaved as they arrive. The resulting stream
1510
- * completes when **both** sources complete. Any error from either source terminates
1511
- * the merged stream immediately.
1512
- *
1513
- * @param other - The publisher to merge with this source.
1514
- * @returns A `Flux<T>` that emits items from both sources concurrently.
1515
- */
1516
- mergeWith(other: Publisher<T>): Flux<T>;
1517
- /**
1518
- * Reduces the stream to a single value using `reducer`, emitting the final result as a `Mono<T>`.
1519
- *
1520
- * The first item becomes the initial accumulator. If the source is empty, the resulting
1521
- * `Mono` completes without emitting a value.
1522
- *
1523
- * @param reducer - Combines the running accumulator with the next item.
1524
- * @returns A `Mono<T>` emitting the final reduced value.
1525
- *
1526
- * @example
1527
- * ```typescript
1528
- * Flux.just(1, 2, 3, 4).reduce((acc, n) => acc + n).subscribe(v => console.log(v));
1529
- * // 10
1530
- * ```
1531
- */
1532
- reduce(reducer: (acc: T, next: T) => T): Mono<T>;
1533
- /**
1534
- * Reduces the stream to a single value of type `A`, using an explicit seed, and emits it as `Mono<A>`.
1535
- *
1536
- * `seedFactory` is called once per subscription to produce the initial accumulator.
1537
- * Unlike {@link reduce}, this always emits a value even if the source is empty (the seed).
1538
- *
1539
- * @param seedFactory - Produces the initial accumulator value per subscription.
1540
- * @param reducer - Combines the running accumulator with the next item.
1541
- * @returns A `Mono<A>` emitting the final reduced value.
1542
- *
1543
- * @example
1544
- * ```typescript
1545
- * Flux.just(1, 2, 3)
1546
- * .reduceWith(() => '', (acc, n) => acc + n)
1547
- * .subscribe(v => console.log(v)); // '123'
1548
- * ```
1549
- */
1550
- reduceWith<A>(seedFactory: () => A, reducer: (acc: A, next: T) => A): Mono<A>;
1551
- /**
1552
- * Ignores all items from this `Flux` and emits a single `void` value on completion.
1553
- *
1554
- * Useful when you care only about the completion signal, not about the emitted items.
1555
- * If the source errors, the error is forwarded.
1556
- *
1557
- * @returns A `Mono<void>` that signals when this `Flux` completes.
1558
- */
1559
- then(): Mono<void>;
1560
- /**
1561
- * Ignores all items from this `Flux`, then subscribes to `other` after this source completes,
1562
- * draining `other` completely and returning a `Mono<void>`.
1563
- *
1564
- * If this source or `other` errors, the error is forwarded.
1565
- *
1566
- * @param other - A `Publisher` to subscribe to after this source completes.
1567
- * @returns A `Mono<void>` that completes once `other` completes.
1568
- */
1569
- thenEmpty(other: Publisher<unknown>): Mono<void>;
1570
- /**
1571
- * Re-subscribes to the source when the publisher returned by `fn` emits,
1572
- * enabling controlled retry with strategies like exponential back-off.
1573
- *
1574
- * `fn` receives a `Flux<Error>` — the stream of errors emitted by each failed attempt.
1575
- * Each emission from the returned publisher triggers a retry.
1576
- * When the returned publisher completes or errors, the retry loop stops.
1577
- *
1578
- * @param fn - Receives an error stream and returns a control publisher.
1579
- * @returns A `Flux<T>` with dynamic retry behaviour.
1580
- *
1581
- * @example
1582
- * ```typescript
1583
- * // Exponential back-off: wait 2^n × 100ms between retries, max 3 retries
1584
- * flux.retryWhen(errors =>
1585
- * errors.zipWith(Flux.range(1, 3), (_, n) => n)
1586
- * .flatMap(n => Mono.delay(n * 100))
1587
- * );
1588
- * ```
1589
- */
1590
- retryWhen(fn: (errors: Flux<Error>) => Publisher<unknown>): Flux<T>;
1591
- /**
1592
- * Re-subscribes to the source each time it completes normally, as controlled by
1593
- * the publisher returned by `fn` (**polling** semantics).
1594
- *
1595
- * `fn` receives a `Flux<void>` — one emission per completion. Each emission triggers
1596
- * a repeat. When the control publisher completes or errors, the loop stops.
1597
- *
1598
- * @param fn - Receives a completion-signal stream and returns a control publisher.
1599
- * @returns A `Flux<T>` that repeats under the control of `fn`.
1600
- *
1601
- * @example
1602
- * ```typescript
1603
- * // Poll every second, stop after 5 times
1604
- * fetchLatest()
1605
- * .toFlux()
1606
- * .repeatWhen(completes => completes.zipWith(Flux.range(1, 5), (_, n) => n)
1607
- * .flatMap(() => Mono.delay(1000)));
1608
- * ```
1609
- */
1610
- repeatWhen(fn: (completes: Flux<void>) => Publisher<unknown>): Flux<T>;
1611
- /**
1612
- * Groups items by a key derived from `keyFn`, emitting a {@link GroupedFlux} per
1613
- * unique key. Each `GroupedFlux` is itself a `Flux<T>` exposing the group `key`.
1614
- *
1615
- * The source is consumed at full speed. Items are routed to the corresponding group's
1616
- * buffer and replayed to any subscriber of that group.
1617
- *
1618
- * @param keyFn - Extracts the group key from each item.
1619
- * @returns A `Flux<GroupedFlux<K, T>>` emitting one group per unique key.
1620
- *
1621
- * @example
1622
- * ```typescript
1623
- * Flux.just(1, 2, 3, 4, 5)
1624
- * .groupBy(n => n % 2 === 0 ? 'even' : 'odd')
1625
- * .flatMap(group => group.collectList().map(items => ({ key: group.key, items })))
1626
- * .subscribe(v => console.log(v));
1627
- * // { key: 'odd', items: [1, 3, 5] }
1628
- * // { key: 'even', items: [2, 4] }
1629
- * ```
1630
- */
1631
- groupBy<K>(keyFn: (value: T) => K): Flux<GroupedFlux<K, T>>;
1632
- /**
1633
- * Buffers items into arrays emitted when either `maxSize` items accumulate
1634
- * **or** `ms` milliseconds elapse since the last flush — whichever comes first.
1635
- *
1636
- * @param maxSize - Maximum items per batch.
1637
- * @param ms - Maximum time (ms) to wait before flushing a partial batch.
1638
- * @returns A `Flux<T[]>` of batches.
1639
- *
1640
- * @example
1641
- * ```typescript
1642
- * // Batch up to 10 items or flush every 500ms
1643
- * eventStream.bufferTimeout(10, 500).subscribe(batch => sendBatch(batch));
1644
- * ```
1645
- */
1646
- bufferTimeout(maxSize: number, ms: number): Flux<T[]>;
1647
- /**
1648
- * Samples this `Flux`, emitting the **most recent** item whenever `trigger` emits.
1649
- *
1650
- * If no item has arrived since the last sample, the trigger emission is ignored.
1651
- * Useful for rate-limiting with external signals (scroll, resize, `requestAnimationFrame`).
1652
- *
1653
- * @param trigger - Controls when to sample; its value is ignored.
1654
- * @returns A `Flux<T>` emitting the latest value at each trigger tick.
1655
- */
1656
- sample(trigger: Publisher<unknown>): Flux<T>;
1657
- /**
1658
- * For each item, subscribes to `triggerFn(item)` and waits for it to emit or complete
1659
- * before forwarding the item downstream (**delayUntil** semantics).
1660
- *
1661
- * Triggers are executed sequentially (concatMap semantics). The trigger's value
1662
- * is ignored — only its timing matters.
1663
- *
1664
- * @param triggerFn - Returns a publisher whose first signal releases the item.
1665
- * @returns A `Flux<T>` where each item is held until its trigger fires.
1666
- *
1667
- * @example
1668
- * ```typescript
1669
- * Flux.just(1, 2, 3)
1670
- * .delayUntil(() => Mono.delay(100))
1671
- * .subscribe(v => console.log(v)); // each item delayed 100ms
1672
- * ```
1673
- */
1674
- delayUntil(triggerFn: (value: T) => Publisher<unknown>): Flux<T>;
1675
- /**
1676
- * Recursively expands each item using `fn`, emitting both the original items and
1677
- * all items produced by the expansion (**breadth-first** order).
1678
- *
1679
- * Useful for **pagination**: call `fn` with the current page to fetch the next,
1680
- * until `fn` returns empty.
1681
- *
1682
- * @param fn - Receives an item; returns a publisher of zero or more new items to expand.
1683
- * @returns A `Flux<T>` of all original and expanded items.
1684
- *
1685
- * @example
1686
- * ```typescript
1687
- * // Fetch all pages recursively
1688
- * fetchPage(1)
1689
- * .toFlux()
1690
- * .expand(page => page.hasNext ? fetchPage(page.nextId).toFlux() : Flux.empty())
1691
- * .subscribe(page => process(page));
1692
- * ```
1693
- */
1694
- expand(fn: (value: T) => Publisher<T>): Flux<T>;
1695
- /**
1696
- * Recursively expands each item using `fn`, emitting both the original items and
1697
- * all items produced by the expansion (**depth-first** order).
1698
- *
1699
- * Unlike {@link expand} (breadth-first), each item's children are emitted immediately
1700
- * after the item itself, before any sibling items are processed. This mirrors a
1701
- * recursive pre-order tree traversal.
1702
- *
1703
- * @param fn - Receives an item; returns a publisher of zero or more new items to expand.
1704
- * @returns A `Flux<T>` of all original and expanded items in depth-first order.
1705
- *
1706
- * @example
1707
- * ```typescript
1708
- * // Tree: 1 → [2, 3], 2 → [4, 5], others → empty
1709
- * Flux.just(1)
1710
- * .expandDeep(n =>
1711
- * n === 1 ? Flux.just(2, 3) :
1712
- * n === 2 ? Flux.just(4, 5) :
1713
- * Flux.empty()
1714
- * )
1715
- * .subscribe(v => console.log(v));
1716
- * // 1 2 4 5 3 (depth-first pre-order)
1717
- * ```
1718
- */
1719
- expandDeep(fn: (value: T) => Publisher<T>): Flux<T>;
1720
- /**
1721
- * Pairs each item with the time elapsed (in ms) since the **previous** item
1722
- * (or since subscription for the first item).
1723
- *
1724
- * @returns A `Flux<[number, T]>` where the first element is elapsed milliseconds.
1725
- *
1726
- * @example
1727
- * ```typescript
1728
- * Flux.interval(100).take(3).elapsed().subscribe(([ms, n]) => console.log(ms, n));
1729
- * // ~100 0 ~100 1 ~100 2
1730
- * ```
1731
- */
1732
- elapsed(): Flux<[number, T]>;
1733
- /**
1734
- * Attaches a `Date.now()` timestamp (in ms since epoch) to each item.
1735
- *
1736
- * @returns A `Flux<[number, T]>` where the first element is the Unix timestamp in ms.
1737
- */
1738
- timestamp(): Flux<[number, T]>;
1739
- /**
1740
- * Wraps each signal (next, error, complete) into a {@link Signal} data object,
1741
- * emitting them all as `onNext` items on a `Flux<Signal<T>>`.
1742
- *
1743
- * After materializing, the resulting `Flux` always completes normally (errors become
1744
- * `Signal.error` items rather than `onError` signals).
1745
- * Use {@link dematerialize} to convert back.
1746
- *
1747
- * @returns A `Flux<Signal<T>>` where every event is represented as a data item.
1748
- */
1749
- materialize(): Flux<Signal<T>>;
1750
- /**
1751
- * Unwraps a `Flux<Signal<R>>` back into a regular `Flux<R>`, restoring
1752
- * `error` and `complete` signals from their materialized form.
1753
- *
1754
- * This is the inverse of {@link materialize}.
1755
- *
1756
- * @returns A `Flux<R>` with signals restored from the `Signal` wrappers.
1757
- */
1758
- dematerialize<R>(this: Flux<Signal<R>>): Flux<R>;
1759
- /**
1760
- * Buffers all upstream items regardless of downstream demand, delivering them
1761
- * when demand becomes available.
1762
- *
1763
- * If `maxSize` is exceeded, an overflow error is signalled downstream.
1764
- *
1765
- * @param maxSize - Maximum buffer capacity (default: unbounded).
1766
- * @returns A `Flux<T>` with explicit backpressure buffering.
1767
- */
1768
- onBackpressureBuffer(maxSize?: number): Flux<T>;
1769
- /**
1770
- * Drops upstream items that arrive when downstream has no outstanding demand.
1771
- *
1772
- * An optional `onDrop` callback is invoked for each dropped item.
1773
- *
1774
- * @param onDrop - Optional callback called with each dropped item.
1775
- * @returns A `Flux<T>` with drop backpressure strategy.
1776
- */
1777
- onBackpressureDrop(onDrop?: (value: T) => void): Flux<T>;
1778
- /**
1779
- * Keeps only the **latest** upstream item when downstream has no demand;
1780
- * older buffered items are overwritten as new ones arrive.
1781
- *
1782
- * @returns A `Flux<T>` with latest-value backpressure strategy.
1783
- */
1784
- onBackpressureLatest(): Flux<T>;
1785
- /**
1786
- * Requests items from upstream in batches of `n`, replenishing when 75% of
1787
- * the batch has been consumed (**prefetch** / **limitRate** semantics).
1788
- *
1789
- * Prevents requesting all items at once from expensive sources.
1790
- *
1791
- * @param n - Prefetch batch size.
1792
- * @returns A `Flux<T>` with controlled upstream demand.
1793
- */
1794
- limitRate(n: number): Flux<T>;
1795
- /**
1796
- * Filters items by runtime type, passing only items that are instances of `constructor`.
1797
- *
1798
- * @typeParam R - The target subtype.
1799
- * @param constructor - The class/constructor to filter by.
1800
- * @returns A `Flux<R>` containing only items that pass `instanceof`.
1801
- *
1802
- * @example
1803
- * ```typescript
1804
- * class Cat { meow() {} }
1805
- * class Dog { bark() {} }
1806
- * Flux.just(new Cat(), new Dog(), new Cat())
1807
- * .ofType(Cat)
1808
- * .subscribe(cat => cat.meow());
1809
- * ```
1810
- */
1811
- ofType<R extends T>(constructor: new (...args: unknown[]) => R): Flux<R>;
1812
- /**
1813
- * Applies a reusable operator function `fn` to this `Flux`, deferred per subscription.
1814
- *
1815
- * `fn` receives this `Flux<T>` (as a `Publisher<T>`) and returns a new `Publisher<R>`.
1816
- * The transformation is re-evaluated on each `subscribe()` call (deferred assembly).
1817
- *
1818
- * @param fn - Operator function to apply.
1819
- * @returns A `Flux<R>` produced by `fn`.
1820
- *
1821
- * @example
1822
- * ```typescript
1823
- * const retryThrice = <T>(source: Publisher<T>) => Flux.from(source).retry(3);
1824
- * Flux.just(1, 2).transformDeferred(retryThrice).subscribe(v => console.log(v));
1825
- * ```
1826
- */
1827
- transformDeferred<R>(fn: (flux: Publisher<T>) => Publisher<R>): Flux<R>;
1828
- }
1829
- /**
1830
- * A `Flux<T>` tagged with a group `key`.
1831
- *
1832
- * Produced by {@link Flux#groupBy} — subscribe to it exactly like any `Flux<T>`;
1833
- * the extra `key` property identifies which group this stream belongs to.
1834
- *
1835
- * Implemented as a plain type intersection rather than a subclass: the runtime
1836
- * object is an ordinary `Flux<T>` with a `key` property attached via
1837
- * `Object.assign`, so no extra prototype chain is required.
1838
- *
1839
- * @typeParam K - The type of the group key.
1840
- * @typeParam T - The type of items in the group.
1841
- */
1842
- type GroupedFlux<K, T> = Flux<T> & {
1843
- readonly key: K;
1844
- };
1845
-
1846
- /**
1847
- * A cold publisher of 0 or 1 items with full backpressure support.
1848
- *
1849
- * A `Mono` emits at most one value followed by `onComplete`, or signals `onError`.
1850
- * Items flow only when the downstream {@link Subscription} issues `request(n)`.
1851
- * The convenience `subscribe(onNext, onError, onComplete)` overloads automatically
1852
- * request `1` so the value starts flowing without extra ceremony.
1853
- *
1854
- * Each `subscribe()` call creates an **independent** run of the pipeline ("cold" semantics).
1855
- *
1856
- * @typeParam T - The type of the single item emitted by this Mono.
1857
- *
1858
- * @example
1859
- * ```typescript
1860
- * Mono.just(42)
1861
- * .map(n => n * 2)
1862
- * .subscribe(v => console.log(v));
1863
- * // 84
1864
- * ```
1865
- */
1866
- declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipePublisher<T> {
1867
- protected constructor(source: Publisher<T>);
1868
- protected defaultDemand(): number;
1869
- protected wrapSource(source: Publisher<T>): Mono<T>;
1870
- /**
1871
- * Creates a `Mono` from a generator function that pushes a value imperatively.
1872
- *
1873
- * The generator receives a {@link Sink} and should call exactly one of:
1874
- * - `sink.next(value)` — emits the value and completes.
1875
- * - `sink.error(err)` — terminates with an error.
1876
- * - `sink.complete()` — completes without emitting a value (empty `Mono`).
1877
- *
1878
- * Delivery is deferred until the downstream subscriber issues `request(n)`.
1879
- * Rule 1.3 is respected — `onSubscribe` is delivered before the generator runs.
1880
- *
1881
- * @param generator - Function that drives the `Mono` via the provided `Sink<T>`.
1882
- * @returns A cold `Mono<T>`.
1883
- *
1884
- * @example
1885
- * ```typescript
1886
- * Mono.generate<number>(sink => sink.next(42)).subscribe(v => console.log(v)); // 42
1887
- * ```
1888
- */
1889
- static generate<T>(generator: (sink: Sink<T>) => void): Mono<T>;
1890
- /**
1891
- * Wraps an existing {@link Publisher} as a `Mono`.
1892
- *
1893
- * @param publisher - Any `Publisher<T>` to adapt.
1894
- * @returns A `Mono<T>` backed by the given publisher.
1895
- */
1896
- static from<T>(publisher: Publisher<T>): Mono<T>;
1897
- /**
1898
- * Creates a `Mono` that emits `value` then completes.
1899
- *
1900
- * @param value - The single item to emit.
1901
- * @returns A cold `Mono<T>`.
1902
- *
1903
- * @example
1904
- * ```typescript
1905
- * Mono.just(42).subscribe(v => console.log(v)); // 42
1906
- * ```
1907
- */
1908
- static just<T>(value: T): Mono<T>;
1909
- /**
1910
- * Creates a `Mono` that emits `value` if it is non-null and non-undefined,
1911
- * or completes empty if `value` is `null` or `undefined`.
1912
- *
1913
- * @param value - The value to emit, or `null`/`undefined` for an empty Mono.
1914
- * @returns A `Mono<T>` that emits the value or completes immediately.
1915
- */
1916
- static justOrEmpty<T>(value: T | null | undefined): Mono<T>;
1917
- /**
1918
- * Creates a `Mono` that completes immediately without emitting any value.
1919
- *
1920
- * @returns An empty, completed `Mono<T>`.
1921
- */
1922
- static empty<T = never>(): Mono<T>;
1923
- /**
1924
- * Creates a `Mono` that signals `onError` immediately upon subscription.
1925
- *
1926
- * @param error - The error to signal (wrapped in an `Error` if not already one).
1927
- * @returns An errored `Mono<T>`.
1928
- */
1929
- static error<T = never>(error: unknown): Mono<T>;
1930
- /**
1931
- * Creates a `Mono` that adapts a `Promise<T>`.
1932
- *
1933
- * The resolved value is emitted as the single item; a rejected promise signals `onError`.
1934
- *
1935
- * @param promise - The promise to adapt.
1936
- * @returns A `Mono<T>` backed by the promise.
1937
- *
1938
- * @example
1939
- * ```typescript
1940
- * Mono.fromPromise(fetch('/api/data').then(r => r.json()))
1941
- * .subscribe(data => console.log(data));
1942
- * ```
1943
- */
1944
- static fromPromise<T>(promise: Promise<T>): Mono<T>;
1945
- /**
1946
- * Lazily creates a new `Mono` per subscription by calling `factory`.
1947
- *
1948
- * Useful when the source depends on mutable state that should be captured
1949
- * at subscribe time rather than at assembly time.
1950
- *
1951
- * @param factory - Called once per subscription to produce the actual `Mono<T>`.
1952
- * @returns A lazy `Mono<T>`.
1953
- */
1954
- static defer<T>(factory: () => Mono<T>): Mono<T>;
1955
- /**
1956
- * Alias for {@link Mono.generate} — imperative push interface.
1957
- *
1958
- * The generator receives a {@link Sink} and should call exactly one of:
1959
- * `sink.next(value)`, `sink.error(err)`, or `sink.complete()`.
1960
- *
1961
- * @param generator - Function that drives the `Mono` via the provided `Sink<T>`.
1962
- * @returns A cold `Mono<T>`.
1963
- */
1964
- static create<T>(generator: (sink: Sink<T>) => void): Mono<T>;
1965
- /**
1966
- * Creates a `Mono<number>` that emits `0` after `ms` milliseconds then completes.
1967
- *
1968
- * Useful for introducing timed delays in reactive pipelines.
1969
- *
1970
- * @param ms - The delay in milliseconds.
1971
- * @returns A `Mono<number>` that emits `0` after the delay.
1972
- *
1973
- * @example
1974
- * ```typescript
1975
- * Mono.delay(500).flatMap(() => Mono.just('hello')).subscribe(v => console.log(v));
1976
- * ```
1977
- */
1978
- static delay(ms: number): Mono<number>;
1979
- /**
1980
- * Creates a `Mono<T>` from a synchronous, potentially-throwing factory function.
1981
- *
1982
- * The factory is called **lazily** at subscription time (not at assembly time).
1983
- * If the factory throws, the exception is forwarded as `onError`.
1984
- *
1985
- * @param fn - Synchronous factory invoked once per subscription.
1986
- * @returns A cold `Mono<T>`.
1987
- *
1988
- * @example
1989
- * ```typescript
1990
- * Mono.fromCallable(() => JSON.parse(rawJson)).subscribe(v => console.log(v));
1991
- * ```
1992
- */
1993
- static fromCallable<T>(fn: () => T): Mono<T>;
1994
- /**
1995
- * Races multiple `Mono`s — emits the first value to arrive, cancelling the rest.
1996
- *
1997
- * If a source completes without emitting, it is excluded from the race.
1998
- * If **all** sources complete empty, the resulting `Mono` also completes empty.
1999
- * If any source errors before another source emits, the error is propagated.
2000
- *
2001
- * @param sources - One or more `Mono<T>` sources to race.
2002
- * @returns A `Mono<T>` that emits the first available value.
2003
- *
2004
- * @example
2005
- * ```typescript
2006
- * Mono.firstWithValue(slow, fast).subscribe(v => console.log(v)); // fast's value
2007
- * ```
2008
- */
2009
- static firstWithValue<T>(...sources: Mono<T>[]): Mono<T>;
2010
- /**
2011
- * Returns a `Mono<void>` that completes when **all** given publishers complete.
2012
- *
2013
- * Emitted values from the sources are ignored. If any source signals `onError`,
2014
- * the error is propagated immediately and all other sources are cancelled.
2015
- * If no sources are provided, completes immediately.
2016
- *
2017
- * @param sources - Zero or more publishers to wait on.
2018
- * @returns A `Mono<void>` that completes once every source has completed.
2019
- *
2020
- * @example
2021
- * ```typescript
2022
- * Mono.when(Mono.delay(100), Mono.delay(200))
2023
- * .subscribe(undefined, undefined, () => console.log('all done'));
2024
- * ```
2025
- */
2026
- static when(...sources: Publisher<unknown>[]): Mono<void>;
2027
- /**
2028
- * Transforms the emitted value using `fn`, producing a `Mono<R>`.
2029
- *
2030
- * If `fn` throws, the exception is forwarded to `onError` and the stream terminates.
2031
- *
2032
- * @param fn - Mapping function applied to the emitted value.
2033
- * @returns A new `Mono<R>`.
2034
- *
2035
- * @example
2036
- * ```typescript
2037
- * Mono.just(42).map(n => n.toString()).subscribe(v => console.log(v)); // '42'
2038
- * ```
2039
- */
2040
- map<R>(fn: (value: T) => R): Mono<R>;
2041
- /**
2042
- * Transforms the emitted value with `fn`, completing empty if the result is `null` or `undefined`.
2043
- *
2044
- * @param fn - Mapping function; returning `null` or `undefined` produces an empty `Mono`.
2045
- * @returns A `Mono<NonNullable<R>>` that completes empty when the mapping returns null.
2046
- */
2047
- mapNotNull<R>(fn: (value: T) => R | null | undefined): Mono<NonNullable<R>>;
2048
- /**
2049
- * Maps the emitted value to an inner `Mono<R>` and flattens the result.
2050
- *
2051
- * When the source emits a value, `fn` is called and the resulting inner `Mono` is
2052
- * subscribed to. The inner `Mono`'s value (or completion/error) is forwarded downstream.
2053
- *
2054
- * @param fn - Maps the emitted value to a `Mono<R>` or any `Publisher<R>`.
2055
- * @returns A `Mono<R>` containing the result of the inner publisher.
2056
- */
2057
- flatMap<R>(fn: (value: T) => Mono<R>): Mono<R>;
2058
- flatMap<R>(fn: (value: T) => Publisher<R>): Mono<R>;
2059
- /**
2060
- * Passes the emitted value downstream only if `predicate` returns `true`;
2061
- * otherwise completes the `Mono` without emitting.
2062
- *
2063
- * @param predicate - Synchronous test applied to the emitted value.
2064
- * @returns A `Mono<T>` that completes empty when the predicate fails.
2065
- */
2066
- filter(predicate: (value: T) => boolean): Mono<T>;
2067
- /**
2068
- * Asynchronous filter: subscribes to `predicate(value)` and forwards the value
2069
- * downstream only if the predicate publisher emits `true`; otherwise completes empty.
2070
- *
2071
- * @param predicate - Returns a `Publisher<boolean>` for the emitted value.
2072
- * @returns A `Mono<T>` that completes empty when the predicate is not satisfied.
2073
- */
2074
- filterWhen(predicate: (value: T) => Publisher<boolean>): Mono<T>;
2075
- /**
2076
- * Unsafe type cast — changes the declared element type to `R` without any
2077
- * runtime conversion. Use only when you are certain the actual runtime type is compatible.
2078
- *
2079
- * @typeParam R - The target element type.
2080
- * @returns This `Mono` re-typed as `Mono<R>`.
2081
- */
2082
- cast<R>(): Mono<R>;
2083
- /**
2084
- * Executes a side-effect function after the stream ends for **any** reason —
2085
- * normal completion or error. Unlike {@link Flux#doFinally}, this does not fire on
2086
- * cancellation (a `Mono` cancel is semantically identical to an unneeded result).
2087
- *
2088
- * Any exception thrown by `fn` is silently swallowed.
2089
- *
2090
- * @param fn - Side-effect to run after any terminal event.
2091
- * @returns A `Mono<T>` with the side effect attached.
2092
- */
2093
- doFinally(fn: () => void): Mono<T>;
2094
- /**
2095
- * Low-level escape hatch for bridging imperative push-based sources into a `Mono<R>`.
2096
- *
2097
- * The `producer` receives three callbacks and must call them to drive the stream.
2098
- * `onRequest` and `onUnsubscribe` let the caller respond to downstream demand and
2099
- * cancellation respectively.
2100
- *
2101
- * @param producer - Callback that receives `(onNext, onError, onComplete)` and drives the stream.
2102
- * @param onRequest - Called when the downstream subscriber requests `n` more items.
2103
- * @param onUnsubscribe - Called when the downstream subscriber cancels.
2104
- * @returns A `Mono<R>` backed by the imperative producer.
2105
- */
2106
- pipe<R>(producer: (onNext: (value: R) => void, onError: (error: Error) => void, onComplete: () => void) => void, onRequest: (request: number) => void, onUnsubscribe: () => void): Mono<R>;
2107
- /**
2108
- * Maps the emitted value to a multi-item publisher and returns the items as a `Flux<R>`.
2109
- *
2110
- * The inner publisher is subscribed to once the source emits its single value.
2111
- * All items from the inner publisher are forwarded downstream. If the source is empty,
2112
- * the resulting `Flux` also completes empty.
2113
- *
2114
- * @param mapper - Maps the emitted value to a `Flux<R>`, `Mono<R>`, or any `Publisher<R>`.
2115
- * @returns A `Flux<R>` containing all items from the inner publisher.
2116
- *
2117
- * @example
2118
- * ```typescript
2119
- * Mono.just(3)
2120
- * .flatMapMany(n => Flux.range(1, n))
2121
- * .subscribe(v => console.log(v)); // 1 2 3
2122
- * ```
2123
- */
2124
- flatMapMany<R>(mapper: (value: T) => Flux<R>): Flux<R>;
2125
- flatMapMany<R>(mapper: (value: T) => Mono<R>): Flux<R>;
2126
- flatMapMany<R>(mapper: (value: T) => Publisher<R>): Flux<R>;
2127
- /**
2128
- * Subscribes to this `Mono` and `other` concurrently and combines their values
2129
- * into a `[T, R]` tuple once both emit.
2130
- *
2131
- * If either `Mono` completes empty, the resulting `Mono` also completes empty.
2132
- * If either errors, the error is forwarded and the other is cancelled.
2133
- *
2134
- * @param other - The second `Mono` to zip with.
2135
- * @returns A `Mono<[T, R]>` emitting the combined tuple.
2136
- *
2137
- * @example
2138
- * ```typescript
2139
- * Mono.just(1).zipWith(Mono.just('a')).subscribe(([n, s]) => console.log(n, s)); // 1 a
2140
- * ```
2141
- */
2142
- zipWith<R>(other: Mono<R>): Mono<[T, R]>;
2143
- /**
2144
- * Emits the source value and uses `fn` to derive a second `Mono`, combining both into a tuple.
2145
- *
2146
- * The source value is passed to `fn` to produce the second `Mono`. Both values are then
2147
- * combined into a `[T, R]` tuple. If either `Mono` is empty or errors, those signals
2148
- * propagate to the subscriber.
2149
- *
2150
- * @param fn - Called with the emitted value to produce the second `Mono<R>`.
2151
- * @returns A `Mono<[T, R]>` emitting both values as a tuple.
2152
- *
2153
- * @example
2154
- * ```typescript
2155
- * Mono.just(42).zipWhen(n => Mono.just(n.toString())).subscribe(([n, s]) => console.log(n, s));
2156
- * // 42 '42'
2157
- * ```
2158
- */
2159
- zipWhen<R>(fn: (value: T) => Mono<R>): Mono<[T, R]>;
2160
- /**
2161
- * Emits `true` if this `Mono` emits a value, `false` if it completes empty.
2162
- *
2163
- * @returns A `Mono<boolean>`.
2164
- */
2165
- hasElement(): Mono<boolean>;
2166
- /**
2167
- * Side effect executed when the `Mono` emits its value.
2168
- *
2169
- * Does **not** affect the emitted value or stream lifecycle.
2170
- * Exceptions thrown by `fn` are forwarded as `onError`.
2171
- *
2172
- * @param fn - Called with the emitted value.
2173
- * @returns A `Mono<T>` with the side effect attached.
2174
- *
2175
- * @example
2176
- * ```typescript
2177
- * Mono.just(42).doOnSuccess(v => console.log('got', v)).subscribe();
2178
- * ```
2179
- */
2180
- doOnSuccess(fn: (value: T) => void): Mono<T>;
2181
- /**
2182
- * Converts a terminal error into a normal `onComplete` signal.
2183
- *
2184
- * If a `predicate` is supplied, only errors for which the predicate returns `true`
2185
- * are swallowed; others are re-propagated as-is.
2186
- *
2187
- * @param predicate - Optional filter; when absent all errors are converted.
2188
- * @returns A `Mono<T>` that completes rather than errors (when predicate matches).
2189
- *
2190
- * @example
2191
- * ```typescript
2192
- * Mono.error(new Error('oops')).onErrorComplete().subscribe(undefined, undefined, () => console.log('done'));
2193
- * ```
2194
- */
2195
- onErrorComplete(predicate?: (e: Error) => boolean): Mono<T>;
2196
- /**
2197
- * Ignores any value emitted by this `Mono` and, upon normal completion,
2198
- * emits `value` instead.
2199
- *
2200
- * Errors from the source are propagated unchanged.
2201
- *
2202
- * @param value - The value to emit after this `Mono` completes.
2203
- * @returns A `Mono<R>` that emits `value` on source completion.
2204
- *
2205
- * @example
2206
- * ```typescript
2207
- * Mono.just('ignored').thenReturn(42).subscribe(v => console.log(v)); // 42
2208
- * ```
2209
- */
2210
- thenReturn<R>(value: R): Mono<R>;
2211
- /**
2212
- * Ignores the value emitted by this `Mono` and, upon completion, subscribes to `other`
2213
- * and forwards its result downstream.
2214
- *
2215
- * If `other` is omitted, returns a `Mono<void>` that completes when this `Mono` completes.
2216
- * Errors from this `Mono` are propagated without subscribing to `other`.
2217
- *
2218
- * @param other - Optional `Mono<V>` to subscribe to after this `Mono` completes.
2219
- * @returns `Mono<void>` when called with no argument; `Mono<V>` when `other` is provided.
2220
- *
2221
- * @example
2222
- * ```typescript
2223
- * // Sequencing: run A, then run B and return B's value
2224
- * Mono.just('ignored').then(Mono.just(42)).subscribe(v => console.log(v)); // 42
2225
- *
2226
- * // Completion signal only
2227
- * Mono.just('ignored').then().subscribe(undefined, undefined, () => console.log('done'));
2228
- * ```
2229
- */
2230
- then(): Mono<void>;
2231
- then<V>(other: Mono<V>): Mono<V>;
2232
- /**
2233
- * Ignores the value (or absence of a value) emitted by this `Mono` and, once
2234
- * the source completes, subscribes to the provided `Publisher<V>` and forwards
2235
- * all of its items and terminal signal downstream as a `Flux<V>`.
2236
- *
2237
- * If the source signals an error the error is forwarded immediately and `other`
2238
- * is never subscribed.
2239
- *
2240
- * This mirrors `Mono#thenMany` from Project Reactor.
2241
- *
2242
- * @param other - The publisher whose items should be delivered after this Mono completes.
2243
- * @returns A `Flux<V>` that forwards all items from `other`.
2244
- *
2245
- * @example
2246
- * ```typescript
2247
- * Mono.just('init')
2248
- * .thenMany(Flux.just(1, 2, 3))
2249
- * .subscribe(v => console.log(v));
2250
- * // 1 2 3
2251
- * ```
2252
- */
2253
- thenMany<V>(other: Publisher<V>): Flux<V>;
2254
- /**
2255
- * Delays delivery of the emitted value by `ms` milliseconds.
2256
- *
2257
- * The delay is introduced **after** the source emits; completion and errors
2258
- * are forwarded without delay.
2259
- *
2260
- * @param ms - Delay in milliseconds.
2261
- * @returns A `Mono<T>` whose value arrives `ms` milliseconds later.
2262
- *
2263
- * @example
2264
- * ```typescript
2265
- * Mono.just('hello').delayElement(200).subscribe(v => console.log(v));
2266
- * ```
2267
- */
2268
- delayElement(ms: number): Mono<T>;
2269
- /**
2270
- * Holds the emitted value until a trigger publisher (returned by `triggerFn`) emits
2271
- * or completes, then forwards the value downstream.
2272
- *
2273
- * If the trigger errors, the error is propagated and the value is discarded.
2274
- * If the source is empty, completes immediately without invoking `triggerFn`.
2275
- *
2276
- * @param triggerFn - Receives the emitted value and returns a trigger `Publisher`.
2277
- * @returns A `Mono<T>` that emits after the trigger fires.
2278
- *
2279
- * @example
2280
- * ```typescript
2281
- * Mono.just(42).delayUntil(() => Mono.delay(300)).subscribe(v => console.log(v));
2282
- * ```
2283
- */
2284
- delayUntil(triggerFn: (value: T) => Publisher<unknown>): Mono<T>;
2285
- /**
2286
- * Falls back to `other` if this `Mono` completes without emitting a value (empty).
2287
- *
2288
- * If this `Mono` emits a value or errors, `other` is never subscribed to.
2289
- *
2290
- * @param other - The fallback `Mono<T>` to subscribe to when the source is empty.
2291
- * @returns A `Mono<T>` that emits from `other` when the source is empty.
2292
- *
2293
- * @example
2294
- * ```typescript
2295
- * Mono.empty<number>().or(Mono.just(99)).subscribe(v => console.log(v)); // 99
2296
- * ```
2297
- */
2298
- or(other: Mono<T>): Mono<T>;
2299
- /**
2300
- * Re-subscribes to this `Mono` on error, using a control publisher to decide
2301
- * whether and when to retry.
2302
- *
2303
- * Each time the source errors, the error is pushed to the control stream returned
2304
- * by `fn`. If that stream emits any item, the source is re-subscribed. If it
2305
- * completes or errors, that terminal signal is forwarded downstream.
2306
- *
2307
- * @param fn - Receives a `Flux<Error>` of upstream errors; returns a control publisher.
2308
- * @returns A `Mono<T>` that retries according to the control signal.
2309
- *
2310
- * @example
2311
- * ```typescript
2312
- * Mono.error(new Error('boom'))
2313
- * .retryWhen(errors => errors.take(3))
2314
- * .subscribe(undefined, e => console.error(e));
2315
- * ```
2316
- */
2317
- retryWhen(fn: (errors: Flux<Error>) => Publisher<unknown>): Mono<T>;
2318
- /**
2319
- * Alias for {@link Mono#toPromise} — returns a `Promise<T | null>` that resolves
2320
- * with the emitted value (or `null` if the `Mono` is empty).
2321
- *
2322
- * @returns A `Promise<T | null>`.
2323
- */
2324
- toFuture(): Promise<T | null>;
2325
- /**
2326
- * Subscribes to this `Mono` and returns a `Promise<T | null>`.
2327
- *
2328
- * The promise resolves with the emitted value, or with `null` if the `Mono` completes empty.
2329
- * The promise rejects if the `Mono` signals an error.
2330
- *
2331
- * @returns A `Promise<T | null>` that resolves when the `Mono` terminates.
2332
- */
2333
- toPromise(): Promise<T | null>;
2334
- }
2335
-
2336
- /**
2337
- * A scheduler that immediately executes tasks.
2338
- * Implements the `Scheduler` interface to execute tasks without any delay.
2339
- */
2340
- declare class ImmediateScheduler implements Scheduler {
2341
- /**
2342
- * Schedules a task to be executed immediately.
2343
- * @param {Function} task - The task function to be executed.
2344
- */
2345
- schedule(task: () => void): void;
2346
- }
2347
-
2348
- /**
2349
- * A scheduler that executes tasks asynchronously using the microtask queue.
2350
- * Implements the `Scheduler` interface and schedules tasks using `Promise.resolve().then(...)`.
2351
- */
2352
- declare class MicroScheduler implements Scheduler {
2353
- /**
2354
- * Schedules a task to be executed asynchronously as a microtask.
2355
- * Uses `Promise.resolve().then(task)` to place the task in the microtask queue.
2356
- * @param {Function} task - The task function to be executed.
2357
- */
2358
- schedule(task: () => void): void;
2359
- }
2360
-
2361
- /**
2362
- * A scheduler that executes tasks asynchronously using the macro task queue.
2363
- * Implements the `Scheduler` interface and schedules tasks using `setTimeout` with a delay of `0`.
2364
- */
2365
- declare class MacroScheduler implements Scheduler {
2366
- /**
2367
- * Schedules a task to be executed asynchronously.
2368
- * Uses `setTimeout` with a delay of `0` to place the task in the macro task queue.
2369
- * @param {Function} task - The task function to be executed.
2370
- */
2371
- schedule(task: () => void): void;
2372
- }
2373
-
2374
- /**
2375
- * A scheduler that executes tasks after a specified delay.
2376
- * Implements the `CancellableScheduler` interface, allowing scheduled tasks to be canceled.
2377
- */
2378
- declare class DelayScheduler implements CancellableScheduler {
2379
- private readonly delay;
2380
- /**
2381
- * Creates a new DelayScheduler.
2382
- * @param {number} delay - The delay duration in milliseconds.
2383
- */
2384
- constructor(delay: number);
2385
- /**
2386
- * Schedules a task to be executed after the specified delay.
2387
- * Returns an object with a cancel method to clear the timeout.
2388
- * @param {Function} task - The task function to be executed.
2389
- * @returns {Object} An object with a `cancel` method to stop the execution.
2390
- */
2391
- schedule(task: () => void): {
2392
- cancel: () => void;
2393
- };
2394
- }
2395
-
2396
- /**
2397
- * A scheduler that executes tasks multiple times with a specified interval.
2398
- * Implements the `CancellableScheduler` interface, allowing scheduled tasks to be canceled.
2399
- */
2400
- declare class IntervalScheduler implements CancellableScheduler {
2401
- private readonly interval;
2402
- /**
2403
- * Creates a new IntervalScheduler.
2404
- * @param {number} delay - The interval duration in milliseconds.
2405
- */
2406
- constructor(delay: number);
2407
- /**
2408
- * Schedules a task to be executed multiple times with a specified interval.
2409
- * Returns an object with a cancel method to clear the timeout.
2410
- * @param {Function} task - The task function to be executed.
2411
- * @returns {Object} An object with a `cancel` method to stop the execution.
2412
- */
2413
- schedule(task: () => void): {
2414
- cancel: () => void;
2415
- };
2416
- }
2417
-
2418
- /**
2419
- * A collection of commonly used schedulers for task execution.
2420
- * Provides methods to create instances of various scheduler types.
2421
- */
2422
- declare const Schedulers: {
2423
- /**
2424
- * Creates an instance of `ImmediateScheduler`.
2425
- * Executes tasks immediately without any delay.
2426
- * @returns {ImmediateScheduler} An instance of ImmediateScheduler.
2427
- */
2428
- immediate: () => ImmediateScheduler;
2429
- /**
2430
- * Creates an instance of `MicroScheduler`.
2431
- * Executes tasks asynchronously using the microtask queue.
2432
- * @returns {MicroScheduler} An instance of MicroScheduler.
2433
- */
2434
- micro: () => MicroScheduler;
2435
- /**
2436
- * Creates an instance of `MacroScheduler`.
2437
- * Executes tasks asynchronously using the macro task queue (via `setTimeout`).
2438
- * @returns {MacroScheduler} An instance of MacroScheduler.
2439
- */
2440
- macro: () => MacroScheduler;
2441
- /**
2442
- * Creates an instance of `DelayScheduler` with a specified delay.
2443
- * Executes tasks after a given delay using `setTimeout`.
2444
- * @param {number} ms - The delay in milliseconds before executing the task.
2445
- * @returns {DelayScheduler} An instance of DelayScheduler.
2446
- */
2447
- delay: (ms: number) => DelayScheduler;
2448
- /**
2449
- * Creates an instance of `IntervalScheduler` with a specified interval.
2450
- * Executes tasks multiple times with a given interval using `setInterval`.
2451
- * @param {number} ms - The interval in milliseconds between task executing.
2452
- * @returns {IntervalScheduler} An instance of IntervalScheduler.
2453
- */
2454
- interval: (ms: number) => IntervalScheduler;
2455
- };
2456
-
2457
- /**
2458
- * A {@link Sink} that is also a {@link Publisher}, with a convenience `asFlux()` accessor.
2459
- * Callers can push values via the `Sink` interface, subscribe via the `Publisher` interface,
2460
- * or obtain a full-featured {@link Flux} view via `asFlux()`.
2461
- */
2462
- type SinkPublisher<T> = Sink<T> & Publisher<T> & {
2463
- asFlux(): Flux<T>;
2464
- };
2465
-
2466
- /**
2467
- * Factory namespace for creating hot or replayable sink/publisher pairs.
2468
- *
2469
- * Each factory returns a {@link SinkPublisher} that implements both {@link Sink} (for pushing values)
2470
- * and {@link Publisher} (for subscribing).
2471
- *
2472
- * @example
2473
- * ```typescript
2474
- * const sink = Sinks.many().multicast().directBestEffort<number>();
2475
- * const flux = Flux.from(sink);
2476
- * flux.subscribe(v => console.log(v));
2477
- * sink.next(1);
2478
- * sink.next(2);
2479
- * sink.complete();
2480
- * ```
2481
- */
2482
- declare const Sinks: {
2483
- /**
2484
- * A sink that immediately completes any subscriber without emitting values.
2485
- * Equivalent to `Flux.empty()` but hot/shared.
2486
- */
2487
- empty: <T>() => SinkPublisher<T>;
2488
- /**
2489
- * A sink for exactly one value. Replays that value (and subsequent completion) to all subscribers.
2490
- * Use for single-result async operations.
2491
- */
2492
- one: <T>() => SinkPublisher<T>;
2493
- /** Creates a multi-subscriber sink factory. */
2494
- many: () => {
2495
- /** Creates multicast (fan-out) sinks that deliver to all current subscribers. */
2496
- multicast: () => {
2497
- /**
2498
- * Delivers each item to all current subscribers simultaneously.
2499
- * If any subscriber cannot accept the item (due to backpressure), **none** of them receive it.
2500
- */
2501
- directAllOrNothing: <T>() => SinkPublisher<T>;
2502
- /**
2503
- * Delivers each item to all current subscribers on a best-effort basis.
2504
- * Subscribers that are not ready (backpressure) are skipped for that item.
2505
- */
2506
- directBestEffort: <T>() => SinkPublisher<T>;
2507
- /**
2508
- * Buffers items and delivers them to all subscribers respecting backpressure.
2509
- *
2510
- * @param bufferSize - Maximum number of items to buffer (default: `256`).
2511
- * @param autoCancel - If `true`, cancels the sink when all subscribers unsubscribe (default: `true`).
2512
- */
2513
- onBackpressureBuffer: <T>(bufferSize?: number, autoCancel?: boolean) => SinkPublisher<T>;
2514
- };
2515
- /** Creates unicast (single-subscriber) sinks. */
2516
- unicast: () => {
2517
- /**
2518
- * Unicast sink that buffers items until the single subscriber requests them.
2519
- * A second `subscribe()` call throws.
2520
- */
2521
- onBackpressureBuffer: <T>() => SinkPublisher<T>;
2522
- /**
2523
- * Unicast sink that errors if an item is pushed when the subscriber has no outstanding demand.
2524
- * A second `subscribe()` call throws.
2525
- */
2526
- onBackpressureError: <T>() => SinkPublisher<T>;
2527
- };
2528
- /** Creates replay sinks that buffer past items for late subscribers. */
2529
- replay: () => {
2530
- /**
2531
- * Replays **all** previously emitted items to each new subscriber.
2532
- * Items are accumulated indefinitely.
2533
- */
2534
- all: <T>() => SinkPublisher<T>;
2535
- /**
2536
- * Replays the most recent `limit` items to each new subscriber.
2537
- *
2538
- * @param limit - Maximum number of items to replay.
2539
- */
2540
- latest: <T>(limit: number) => SinkPublisher<T>;
2541
- /**
2542
- * Replays the most recent item (or `value` if nothing has been emitted yet) to each new subscriber.
2543
- *
2544
- * @param value - Default value replayed until the first `next()` call.
2545
- */
2546
- latestOrDefault: <T>(value: T) => SinkPublisher<T>;
2547
- /**
2548
- * Alias for {@link latest}. Replays the most recent `limit` items.
2549
- *
2550
- * @param limit - Maximum number of items to replay.
2551
- */
2552
- limit: <T>(limit: number) => SinkPublisher<T>;
2553
- };
2554
- };
2555
- };
2556
-
2557
- export { type CancellableScheduler, type DOMEventTargetLike, type EventSourceLike, Flux, type FluxSink, type GroupedFlux, Mono, type NodeEventEmitterLike, type Publisher, type Scheduler, Schedulers, Signal, type Sink, type SinkPublisher, Sinks, type Subscriber, type Subscription, type WebSocketLike };
2
+ * @packageDocumentation
3
+ * Public package entrypoint.
4
+ *
5
+ * Only the stable consumer-facing Reactor surface is re-exported here. Internal
6
+ * helpers, implementation classes, errors, hooks and sink detail types are kept
7
+ * out of the package root on purpose.
8
+ */
9
+ export type { Disposable } from "./core/types.js";
10
+ export { Context } from "./context/context.js";
11
+ export type { Publisher } from "./publisher/publisher.js";
12
+ export type { Subscriber } from "./subscription/subscriber.js";
13
+ export type { Subscription } from "./subscription/subscription.js";
14
+ export { Flux } from "./publisher/flux-entrypoint.js";
15
+ export { Mono } from "./publisher/mono-entrypoint.js";
16
+ export { Sinks } from "./sinks/index.js";
17
+ export { Schedulers } from "./schedulers/index.js";
18
+ //# sourceMappingURL=index.d.ts.map