@lmvz-ds/components 0.12.5 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm/Effect-BhQLGXPs.js → cjs/assets-CB5ikzmP.js} +857 -4832
- package/dist/cjs/{icons-7wUEcWEo.js → icons-DM_TTn48.js} +363 -113
- package/dist/cjs/{index-CVw4GUo6.js → index-Bp6Dd2i1.js} +4 -2
- package/dist/cjs/{index-9ZJx0550.js → index-D3BMpL5w.js} +0 -3
- package/dist/cjs/index.cjs.js +4 -6
- package/dist/cjs/lmvz-action.cjs.entry.js +1 -1
- package/dist/cjs/lmvz-button.cjs.entry.js +7 -10
- package/dist/cjs/lmvz-card.cjs.entry.js +3 -4
- package/dist/cjs/lmvz-chip.cjs.entry.js +1 -1
- package/dist/cjs/lmvz-components.cjs.js +1 -1
- package/dist/cjs/lmvz-header.cjs.entry.js +13 -12
- package/dist/cjs/lmvz-icon.cjs.entry.js +8 -10
- package/dist/cjs/lmvz-input.cjs.entry.js +8 -11
- package/dist/cjs/lmvz-menuitem.cjs.entry.js +5 -7
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/reactive-controller-host-BMDEj1kX.js +168 -0
- package/dist/collection/components/lmvz-button/lmvz-button.js +3 -3
- package/dist/collection/components/lmvz-header/lmvz-header.js +11 -8
- package/dist/collection/components/lmvz-icon/lmvz-icon.js +2 -2
- package/dist/collection/components/lmvz-icon/test/icons.unit.js +21 -12
- package/dist/collection/components/lmvz-input/lmvz-input.css +5 -2
- package/dist/collection/components/lmvz-input/lmvz-input.js +3 -3
- package/dist/collection/components/lmvz-menuitem/lmvz-menuitem.js +3 -3
- package/dist/collection/integration/header-integration.js +3 -1
- package/dist/collection/utils/{validation → aria}/aria-validation-controller.js +15 -34
- package/dist/collection/utils/{list-keyboard-controller.js → aria/list-keyboard-controller.js} +1 -1
- package/dist/collection/utils/{http.test.js → http.unit.js} +7 -6
- package/dist/components/index.js +1 -1
- package/dist/components/lmvz-action.js +1 -1
- package/dist/components/lmvz-button.js +1 -1
- package/dist/components/lmvz-card.js +1 -1
- package/dist/components/lmvz-chip.js +1 -1
- package/dist/components/lmvz-header.js +1 -1
- package/dist/components/lmvz-icon.js +1 -1
- package/dist/components/lmvz-input.js +1 -1
- package/dist/components/lmvz-menuitem.js +1 -1
- package/dist/components/p-BBDH9X49.js +1 -0
- package/dist/components/{p-DMLRPGid.js → p-BfTCfPZ1.js} +1 -1
- package/dist/components/p-Bs6_m7Uw.js +1 -0
- package/dist/components/p-CMteT-Yo.js +1 -0
- package/dist/components/p-vi4YzJmv.js +1 -0
- package/dist/{cjs/Effect-CNhHt4Xb.js → esm/assets-ozES4zSA.js} +785 -5032
- package/dist/esm/{icons-Bx1wWPM2.js → icons-kpJZ1u9g.js} +268 -18
- package/dist/esm/{index-Bt32KzDW.js → index-BfTCfPZ1.js} +3 -1
- package/dist/esm/{index-smGPjoDX.js → index-T5ljELGS.js} +1 -3
- package/dist/esm/index.js +3 -5
- package/dist/esm/lmvz-action.entry.js +1 -1
- package/dist/esm/lmvz-button.entry.js +5 -8
- package/dist/esm/lmvz-card.entry.js +2 -3
- package/dist/esm/lmvz-chip.entry.js +1 -1
- package/dist/esm/lmvz-components.js +2 -2
- package/dist/esm/lmvz-header.entry.js +11 -10
- package/dist/esm/lmvz-icon.entry.js +5 -7
- package/dist/esm/lmvz-input.entry.js +6 -9
- package/dist/esm/lmvz-menuitem.entry.js +3 -5
- package/dist/esm/loader.js +2 -2
- package/dist/esm/reactive-controller-host-CZ3dGAjR.js +165 -0
- package/dist/lmvz-components/index.esm.js +1 -1
- package/dist/lmvz-components/lmvz-components.esm.js +1 -1
- package/dist/lmvz-components/p-16878d4c.entry.js +1 -0
- package/dist/lmvz-components/p-4ad8c332.entry.js +1 -0
- package/dist/lmvz-components/p-5eee0752.entry.js +1 -0
- package/dist/lmvz-components/p-8ea1a349.entry.js +1 -0
- package/dist/lmvz-components/{p-d4b68381.entry.js → p-980688a0.entry.js} +1 -1
- package/dist/lmvz-components/{p-DMLRPGid.js → p-BfTCfPZ1.js} +1 -1
- package/dist/lmvz-components/p-CZ3dGAjR.js +1 -0
- package/dist/lmvz-components/p-D9lc4ayG.js +1 -0
- package/dist/lmvz-components/p-T5ljELGS.js +2 -0
- package/dist/lmvz-components/p-a34542fa.entry.js +1 -0
- package/dist/lmvz-components/p-d2bf6a3f.entry.js +1 -0
- package/dist/lmvz-components/{p-9faac8f3.entry.js → p-feda2ec5.entry.js} +1 -1
- package/dist/lmvz-components/p-iviTjlUy.js +1 -0
- package/dist/manifest.json +1 -1
- package/dist/types/components/lmvz-button/lmvz-button.d.ts +2 -2
- package/dist/types/components/lmvz-header/lmvz-header.d.ts +5 -4
- package/dist/types/components/lmvz-icon/lmvz-icon.d.ts +1 -1
- package/dist/types/components/lmvz-input/lmvz-input.d.ts +1 -1
- package/dist/types/components/lmvz-menuitem/lmvz-menuitem.d.ts +2 -2
- package/dist/types/utils/{validation → aria}/aria-validation-controller.d.ts +1 -5
- package/dist/types/utils/{element-activation-controller.d.ts → aria/element-activation-controller.d.ts} +2 -2
- package/dist/types/utils/{list-keyboard-controller.d.ts → aria/list-keyboard-controller.d.ts} +1 -1
- package/hydrate/index.js +9610 -50169
- package/hydrate/index.mjs +9610 -50169
- package/package.json +17 -18
- package/readme.md +18 -0
- package/dist/cjs/MutableQueue-Bk9tBfaK.js +0 -462
- package/dist/cjs/_commonjsHelpers-CFO10eej.js +0 -7
- package/dist/cjs/aria-validation-controller-B3hMkau3.js +0 -2930
- package/dist/cjs/assets-BguFB3wV.js +0 -71
- package/dist/cjs/axe-BNqwbBGU.js +0 -32834
- package/dist/components/p-3I3wZmp8.js +0 -1
- package/dist/components/p-B85MJLTf.js +0 -1
- package/dist/components/p-BaPwpeMs.js +0 -1
- package/dist/components/p-CAi33KTt.js +0 -1
- package/dist/components/p-CdofjRtQ.js +0 -1
- package/dist/components/p-D1HbKFuh.js +0 -12
- package/dist/components/p-UwhTS2ue.js +0 -1
- package/dist/esm/MutableQueue-CNlEFklh.js +0 -431
- package/dist/esm/_commonjsHelpers-B85MJLTf.js +0 -5
- package/dist/esm/aria-validation-controller-iA4YWFG-.js +0 -2927
- package/dist/esm/assets-Iu8neKuE.js +0 -67
- package/dist/esm/axe-cRQ9Ux1I.js +0 -32832
- package/dist/lmvz-components/p-1a10fcbd.entry.js +0 -1
- package/dist/lmvz-components/p-274c36df.entry.js +0 -1
- package/dist/lmvz-components/p-2ba68483.entry.js +0 -1
- package/dist/lmvz-components/p-4XIjw3k8.js +0 -1
- package/dist/lmvz-components/p-51Fb_qqD.js +0 -1
- package/dist/lmvz-components/p-77e26e71.entry.js +0 -1
- package/dist/lmvz-components/p-B85MJLTf.js +0 -1
- package/dist/lmvz-components/p-BhQLGXPs.js +0 -1
- package/dist/lmvz-components/p-CXWyvf0D.js +0 -1
- package/dist/lmvz-components/p-D1HbKFuh.js +0 -12
- package/dist/lmvz-components/p-D7I-Bc5i.js +0 -1
- package/dist/lmvz-components/p-a5fe62b6.entry.js +0 -1
- package/dist/lmvz-components/p-c8b78793.entry.js +0 -1
- package/dist/lmvz-components/p-smGPjoDX.js +0 -2
- /package/dist/collection/utils/{element-activation-controller.js → aria/element-activation-controller.js} +0 -0
- /package/dist/types/utils/{http.test.d.ts → http.unit.d.ts} +0 -0
|
@@ -1,2930 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-9ZJx0550.js');
|
|
4
|
-
var Effect = require('./Effect-CNhHt4Xb.js');
|
|
5
|
-
var MutableQueue = require('./MutableQueue-Bk9tBfaK.js');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @since 2.0.0
|
|
9
|
-
* @category constructors
|
|
10
|
-
*/
|
|
11
|
-
const make$3 = Effect.make$1;
|
|
12
|
-
/**
|
|
13
|
-
* @since 2.0.0
|
|
14
|
-
* @category getters
|
|
15
|
-
*/
|
|
16
|
-
const get = Effect.get$1;
|
|
17
|
-
/**
|
|
18
|
-
* @since 2.0.0
|
|
19
|
-
* @category utils
|
|
20
|
-
*/
|
|
21
|
-
const modify = Effect.modify;
|
|
22
|
-
/**
|
|
23
|
-
* @since 2.0.0
|
|
24
|
-
* @category utils
|
|
25
|
-
*/
|
|
26
|
-
const update = Effect.update;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a `Fail` cause from an expected error.
|
|
30
|
-
*
|
|
31
|
-
* **Details**
|
|
32
|
-
*
|
|
33
|
-
* This function constructs a `Cause` carrying an error of type `E`. It's used
|
|
34
|
-
* when you want to represent a known or anticipated failure in your effectful
|
|
35
|
-
* computations.
|
|
36
|
-
*
|
|
37
|
-
* @see {@link isFailure} Check if a `Cause` contains a failure
|
|
38
|
-
*
|
|
39
|
-
* @since 2.0.0
|
|
40
|
-
* @category Constructors
|
|
41
|
-
*/
|
|
42
|
-
const fail$1 = Effect.fail;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a `Die` cause from an unexpected error.
|
|
45
|
-
*
|
|
46
|
-
* **Details**
|
|
47
|
-
*
|
|
48
|
-
* This function wraps an unhandled or unknown defect (like a runtime crash)
|
|
49
|
-
* into a `Cause`. It's useful for capturing unforeseen issues in a structured
|
|
50
|
-
* way.
|
|
51
|
-
*
|
|
52
|
-
* @see {@link isDie} Check if a `Cause` contains a defect
|
|
53
|
-
*
|
|
54
|
-
* @since 2.0.0
|
|
55
|
-
* @category Constructors
|
|
56
|
-
*/
|
|
57
|
-
const die = Effect.die;
|
|
58
|
-
/**
|
|
59
|
-
* Creates an `Interrupt` cause from a `FiberId`.
|
|
60
|
-
*
|
|
61
|
-
* **Details**
|
|
62
|
-
*
|
|
63
|
-
* This function represents a fiber that has been interrupted. It stores the
|
|
64
|
-
* identifier of the interrupted fiber, enabling precise tracking of concurrent
|
|
65
|
-
* cancellations.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link isInterrupted} Check if a `Cause` contains an interruption
|
|
68
|
-
*
|
|
69
|
-
* @since 2.0.0
|
|
70
|
-
* @category Constructors
|
|
71
|
-
*/
|
|
72
|
-
const interrupt$1 = Effect.interrupt;
|
|
73
|
-
/**
|
|
74
|
-
* Checks if a `Cause` is a `Die` type.
|
|
75
|
-
*
|
|
76
|
-
* @see {@link die} Create a new `Die` cause
|
|
77
|
-
*
|
|
78
|
-
* @since 2.0.0
|
|
79
|
-
* @category Guards
|
|
80
|
-
*/
|
|
81
|
-
const isDieType = Effect.isDieType;
|
|
82
|
-
/**
|
|
83
|
-
* Checks if a `Cause` contains an interruption.
|
|
84
|
-
*
|
|
85
|
-
* **Details**
|
|
86
|
-
*
|
|
87
|
-
* This function returns `true` if the `Cause` includes any fiber interruptions.
|
|
88
|
-
*
|
|
89
|
-
* @since 2.0.0
|
|
90
|
-
* @category Getters
|
|
91
|
-
*/
|
|
92
|
-
const isInterrupted = Effect.isInterrupted;
|
|
93
|
-
/**
|
|
94
|
-
* Checks if a `Cause` contains only interruptions.
|
|
95
|
-
*
|
|
96
|
-
* **Details**
|
|
97
|
-
*
|
|
98
|
-
* This function returns `true` if the `Cause` has been interrupted but does not
|
|
99
|
-
* contain any other failures, such as `Fail` or `Die`. It's helpful for
|
|
100
|
-
* verifying purely "cancellation" scenarios.
|
|
101
|
-
*
|
|
102
|
-
* @since 2.0.0
|
|
103
|
-
* @category Getters
|
|
104
|
-
*/
|
|
105
|
-
const isInterruptedOnly = Effect.isInterruptedOnly;
|
|
106
|
-
/**
|
|
107
|
-
* Collects all `FiberId`s responsible for interrupting a fiber.
|
|
108
|
-
*
|
|
109
|
-
* **Details**
|
|
110
|
-
*
|
|
111
|
-
* This function returns a set of IDs indicating which fibers caused
|
|
112
|
-
* interruptions within this `Cause`. It's useful for debugging concurrency
|
|
113
|
-
* issues or tracing cancellations.
|
|
114
|
-
*
|
|
115
|
-
* @since 2.0.0
|
|
116
|
-
* @category Getters
|
|
117
|
-
*/
|
|
118
|
-
const interruptors = Effect.interruptors;
|
|
119
|
-
/**
|
|
120
|
-
* Splits a `Cause` into either its first `Fail` error or the rest of the cause
|
|
121
|
-
* (which might only contain `Die` or `Interrupt`).
|
|
122
|
-
*
|
|
123
|
-
* **Details**
|
|
124
|
-
*
|
|
125
|
-
* This function either returns the checked error (`E`) or the remaining
|
|
126
|
-
* `Cause<never>` with defects/interruptions. It helps you decide if there's a
|
|
127
|
-
* recoverable path or if only unhandled issues remain.
|
|
128
|
-
*
|
|
129
|
-
* @since 2.0.0
|
|
130
|
-
* @category Getters
|
|
131
|
-
*/
|
|
132
|
-
const failureOrCause = Effect.failureOrCause;
|
|
133
|
-
/**
|
|
134
|
-
* Strips out failures with an error of `None` from a `Cause<Option<E>>`.
|
|
135
|
-
*
|
|
136
|
-
* **Details**
|
|
137
|
-
*
|
|
138
|
-
* This function turns a `Cause<Option<E>>` into an `Option<Cause<E>>`. If the
|
|
139
|
-
* cause only contains failures of `None`, it becomes `None`; otherwise, it
|
|
140
|
-
* returns a `Cause` of the remaining errors. It's helpful when working with
|
|
141
|
-
* optional errors and filtering out certain error paths.
|
|
142
|
-
*
|
|
143
|
-
* @since 2.0.0
|
|
144
|
-
* @category Getters
|
|
145
|
-
*/
|
|
146
|
-
const flipCauseOption = Effect.flipCauseOption;
|
|
147
|
-
/**
|
|
148
|
-
* Transforms the errors in a `Cause` using a user-provided function.
|
|
149
|
-
*
|
|
150
|
-
* **Details**
|
|
151
|
-
*
|
|
152
|
-
* This function applies `f` to each `Fail` error while leaving defects (`Die`)
|
|
153
|
-
* and interruptions untouched. It's useful for changing or simplifying error
|
|
154
|
-
* types in your effectful workflows.
|
|
155
|
-
*
|
|
156
|
-
* @see {@link as} Replace errors with a single constant
|
|
157
|
-
*
|
|
158
|
-
* @since 2.0.0
|
|
159
|
-
* @category Mapping
|
|
160
|
-
*/
|
|
161
|
-
const map$2 = Effect.map$1;
|
|
162
|
-
|
|
163
|
-
const _await = Effect._await;
|
|
164
|
-
/**
|
|
165
|
-
* Inherits values from all `FiberRef` instances into current fiber. This
|
|
166
|
-
* will resume immediately.
|
|
167
|
-
*
|
|
168
|
-
* @since 2.0.0
|
|
169
|
-
* @category destructors
|
|
170
|
-
*/
|
|
171
|
-
const inheritAll = Effect.inheritAll;
|
|
172
|
-
/**
|
|
173
|
-
* Interrupts the fiber from whichever fiber is calling this method. If the
|
|
174
|
-
* fiber has already exited, the returned effect will resume immediately.
|
|
175
|
-
* Otherwise, the effect will resume when the fiber exits.
|
|
176
|
-
*
|
|
177
|
-
* @since 2.0.0
|
|
178
|
-
* @category interruption
|
|
179
|
-
*/
|
|
180
|
-
const interrupt = Effect.interruptFiber;
|
|
181
|
-
/**
|
|
182
|
-
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
|
183
|
-
* fiber has already exited, the returned effect will resume immediately.
|
|
184
|
-
* Otherwise, the effect will resume when the fiber exits.
|
|
185
|
-
*
|
|
186
|
-
* @since 2.0.0
|
|
187
|
-
* @category interruption
|
|
188
|
-
*/
|
|
189
|
-
const interruptAs = Effect.interruptAsFiber;
|
|
190
|
-
/**
|
|
191
|
-
* Joins the fiber, which suspends the joining fiber until the result of the
|
|
192
|
-
* fiber has been determined. Attempting to join a fiber that has erred will
|
|
193
|
-
* result in a catchable error. Joining an interrupted fiber will result in an
|
|
194
|
-
* "inner interruption" of this fiber, unlike interruption triggered by
|
|
195
|
-
* another fiber, "inner interruption" can be caught and recovered.
|
|
196
|
-
*
|
|
197
|
-
* @since 2.0.0
|
|
198
|
-
* @category destructors
|
|
199
|
-
*/
|
|
200
|
-
const join = Effect.join;
|
|
201
|
-
|
|
202
|
-
/** @internal */
|
|
203
|
-
const EnqueueSymbolKey = "effect/QueueEnqueue";
|
|
204
|
-
/** @internal */
|
|
205
|
-
const EnqueueTypeId = /*#__PURE__*/Symbol.for(EnqueueSymbolKey);
|
|
206
|
-
/** @internal */
|
|
207
|
-
const DequeueSymbolKey = "effect/QueueDequeue";
|
|
208
|
-
/** @internal */
|
|
209
|
-
const DequeueTypeId = /*#__PURE__*/Symbol.for(DequeueSymbolKey);
|
|
210
|
-
/** @internal */
|
|
211
|
-
const QueueStrategySymbolKey = "effect/QueueStrategy";
|
|
212
|
-
/** @internal */
|
|
213
|
-
const QueueStrategyTypeId = /*#__PURE__*/Symbol.for(QueueStrategySymbolKey);
|
|
214
|
-
/** @internal */
|
|
215
|
-
const BackingQueueSymbolKey = "effect/BackingQueue";
|
|
216
|
-
/** @internal */
|
|
217
|
-
const BackingQueueTypeId = /*#__PURE__*/Symbol.for(BackingQueueSymbolKey);
|
|
218
|
-
const queueStrategyVariance = {
|
|
219
|
-
/* c8 ignore next */
|
|
220
|
-
_A: _ => _
|
|
221
|
-
};
|
|
222
|
-
const backingQueueVariance = {
|
|
223
|
-
/* c8 ignore next */
|
|
224
|
-
_A: _ => _
|
|
225
|
-
};
|
|
226
|
-
/** @internal */
|
|
227
|
-
const enqueueVariance = {
|
|
228
|
-
/* c8 ignore next */
|
|
229
|
-
_In: _ => _
|
|
230
|
-
};
|
|
231
|
-
/** @internal */
|
|
232
|
-
const dequeueVariance = {
|
|
233
|
-
/* c8 ignore next */
|
|
234
|
-
_Out: _ => _
|
|
235
|
-
};
|
|
236
|
-
/** @internal */
|
|
237
|
-
class QueueImpl extends Effect.Class {
|
|
238
|
-
queue;
|
|
239
|
-
takers;
|
|
240
|
-
shutdownHook;
|
|
241
|
-
shutdownFlag;
|
|
242
|
-
strategy;
|
|
243
|
-
[EnqueueTypeId] = enqueueVariance;
|
|
244
|
-
[DequeueTypeId] = dequeueVariance;
|
|
245
|
-
constructor(/** @internal */
|
|
246
|
-
queue, /** @internal */
|
|
247
|
-
takers, /** @internal */
|
|
248
|
-
shutdownHook, /** @internal */
|
|
249
|
-
shutdownFlag, /** @internal */
|
|
250
|
-
strategy) {
|
|
251
|
-
super();
|
|
252
|
-
this.queue = queue;
|
|
253
|
-
this.takers = takers;
|
|
254
|
-
this.shutdownHook = shutdownHook;
|
|
255
|
-
this.shutdownFlag = shutdownFlag;
|
|
256
|
-
this.strategy = strategy;
|
|
257
|
-
}
|
|
258
|
-
pipe() {
|
|
259
|
-
return Effect.pipeArguments(this, arguments);
|
|
260
|
-
}
|
|
261
|
-
commit() {
|
|
262
|
-
return this.take;
|
|
263
|
-
}
|
|
264
|
-
capacity() {
|
|
265
|
-
return this.queue.capacity();
|
|
266
|
-
}
|
|
267
|
-
get size() {
|
|
268
|
-
return Effect.suspend(() => Effect.catchAll$1(this.unsafeSize(), () => Effect.interrupt$1));
|
|
269
|
-
}
|
|
270
|
-
unsafeSize() {
|
|
271
|
-
if (Effect.get$2(this.shutdownFlag)) {
|
|
272
|
-
return Effect.none();
|
|
273
|
-
}
|
|
274
|
-
return Effect.some(this.queue.length() - MutableQueue.length(this.takers) + this.strategy.surplusSize());
|
|
275
|
-
}
|
|
276
|
-
get isEmpty() {
|
|
277
|
-
return Effect.map(this.size, size => size <= 0);
|
|
278
|
-
}
|
|
279
|
-
get isFull() {
|
|
280
|
-
return Effect.map(this.size, size => size >= this.capacity());
|
|
281
|
-
}
|
|
282
|
-
get shutdown() {
|
|
283
|
-
return Effect.uninterruptible(Effect.withFiberRuntime(state => {
|
|
284
|
-
Effect.pipe(this.shutdownFlag, Effect.set$1(true));
|
|
285
|
-
return Effect.pipe(Effect.forEachConcurrentDiscard(unsafePollAll(this.takers), d => Effect.deferredInterruptWith(d, state.id()), false, false), Effect.zipRight(this.strategy.shutdown), Effect.whenEffect(Effect.deferredSucceed(this.shutdownHook, void 0)), Effect.asVoid);
|
|
286
|
-
}));
|
|
287
|
-
}
|
|
288
|
-
get isShutdown() {
|
|
289
|
-
return Effect.sync(() => Effect.get$2(this.shutdownFlag));
|
|
290
|
-
}
|
|
291
|
-
get awaitShutdown() {
|
|
292
|
-
return Effect.deferredAwait(this.shutdownHook);
|
|
293
|
-
}
|
|
294
|
-
isActive() {
|
|
295
|
-
return !Effect.get$2(this.shutdownFlag);
|
|
296
|
-
}
|
|
297
|
-
unsafeOffer(value) {
|
|
298
|
-
if (Effect.get$2(this.shutdownFlag)) {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
let noRemaining;
|
|
302
|
-
if (this.queue.length() === 0) {
|
|
303
|
-
const taker = Effect.pipe(this.takers, MutableQueue.poll(MutableQueue.EmptyMutableQueue));
|
|
304
|
-
if (taker !== MutableQueue.EmptyMutableQueue) {
|
|
305
|
-
unsafeCompleteDeferred(taker, value);
|
|
306
|
-
noRemaining = true;
|
|
307
|
-
} else {
|
|
308
|
-
noRemaining = false;
|
|
309
|
-
}
|
|
310
|
-
} else {
|
|
311
|
-
noRemaining = false;
|
|
312
|
-
}
|
|
313
|
-
if (noRemaining) {
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
// Not enough takers, offer to the queue
|
|
317
|
-
const succeeded = this.queue.offer(value);
|
|
318
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
319
|
-
return succeeded;
|
|
320
|
-
}
|
|
321
|
-
offer(value) {
|
|
322
|
-
return Effect.suspend(() => {
|
|
323
|
-
if (Effect.get$2(this.shutdownFlag)) {
|
|
324
|
-
return Effect.interrupt$1;
|
|
325
|
-
}
|
|
326
|
-
let noRemaining;
|
|
327
|
-
if (this.queue.length() === 0) {
|
|
328
|
-
const taker = Effect.pipe(this.takers, MutableQueue.poll(MutableQueue.EmptyMutableQueue));
|
|
329
|
-
if (taker !== MutableQueue.EmptyMutableQueue) {
|
|
330
|
-
unsafeCompleteDeferred(taker, value);
|
|
331
|
-
noRemaining = true;
|
|
332
|
-
} else {
|
|
333
|
-
noRemaining = false;
|
|
334
|
-
}
|
|
335
|
-
} else {
|
|
336
|
-
noRemaining = false;
|
|
337
|
-
}
|
|
338
|
-
if (noRemaining) {
|
|
339
|
-
return Effect.succeed$1(true);
|
|
340
|
-
}
|
|
341
|
-
// Not enough takers, offer to the queue
|
|
342
|
-
const succeeded = this.queue.offer(value);
|
|
343
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
344
|
-
return succeeded ? Effect.succeed$1(true) : this.strategy.handleSurplus([value], this.queue, this.takers, this.shutdownFlag);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
offerAll(iterable) {
|
|
348
|
-
return Effect.suspend(() => {
|
|
349
|
-
if (Effect.get$2(this.shutdownFlag)) {
|
|
350
|
-
return Effect.interrupt$1;
|
|
351
|
-
}
|
|
352
|
-
const values = Effect.fromIterable(iterable);
|
|
353
|
-
const pTakers = this.queue.length() === 0 ? Effect.fromIterable(unsafePollN(this.takers, values.length)) : Effect.empty$1;
|
|
354
|
-
const [forTakers, remaining] = Effect.pipe(values, Effect.splitAt(pTakers.length));
|
|
355
|
-
for (let i = 0; i < pTakers.length; i++) {
|
|
356
|
-
const taker = pTakers[i];
|
|
357
|
-
const item = forTakers[i];
|
|
358
|
-
unsafeCompleteDeferred(taker, item);
|
|
359
|
-
}
|
|
360
|
-
if (remaining.length === 0) {
|
|
361
|
-
return Effect.succeed$1(true);
|
|
362
|
-
}
|
|
363
|
-
// Not enough takers, offer to the queue
|
|
364
|
-
const surplus = this.queue.offerAll(remaining);
|
|
365
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
366
|
-
return Effect.isEmpty(surplus) ? Effect.succeed$1(true) : this.strategy.handleSurplus(surplus, this.queue, this.takers, this.shutdownFlag);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
get take() {
|
|
370
|
-
return Effect.withFiberRuntime(state => {
|
|
371
|
-
if (Effect.get$2(this.shutdownFlag)) {
|
|
372
|
-
return Effect.interrupt$1;
|
|
373
|
-
}
|
|
374
|
-
const item = this.queue.poll(MutableQueue.EmptyMutableQueue);
|
|
375
|
-
if (item !== MutableQueue.EmptyMutableQueue) {
|
|
376
|
-
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers);
|
|
377
|
-
return Effect.succeed$1(item);
|
|
378
|
-
} else {
|
|
379
|
-
// Add the deferred to takers, then:
|
|
380
|
-
// - Try to take again in case a value was added since
|
|
381
|
-
// - Wait for the deferred to be completed
|
|
382
|
-
// - Clean up resources in case of interruption
|
|
383
|
-
const deferred = Effect.deferredUnsafeMake(state.id());
|
|
384
|
-
return Effect.pipe(Effect.suspend(() => {
|
|
385
|
-
Effect.pipe(this.takers, MutableQueue.offer(deferred));
|
|
386
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers);
|
|
387
|
-
return Effect.get$2(this.shutdownFlag) ? Effect.interrupt$1 : Effect.deferredAwait(deferred);
|
|
388
|
-
}), Effect.onInterrupt(() => {
|
|
389
|
-
return Effect.sync(() => unsafeRemove(this.takers, deferred));
|
|
390
|
-
}));
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
get takeAll() {
|
|
395
|
-
return Effect.suspend(() => {
|
|
396
|
-
return Effect.get$2(this.shutdownFlag) ? Effect.interrupt$1 : Effect.sync(() => {
|
|
397
|
-
const values = this.queue.pollUpTo(Number.POSITIVE_INFINITY);
|
|
398
|
-
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers);
|
|
399
|
-
return Effect.fromIterable$1(values);
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
takeUpTo(max) {
|
|
404
|
-
return Effect.suspend(() => Effect.get$2(this.shutdownFlag) ? Effect.interrupt$1 : Effect.sync(() => {
|
|
405
|
-
const values = this.queue.pollUpTo(max);
|
|
406
|
-
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers);
|
|
407
|
-
return Effect.fromIterable$1(values);
|
|
408
|
-
}));
|
|
409
|
-
}
|
|
410
|
-
takeBetween(min, max) {
|
|
411
|
-
return Effect.suspend(() => takeRemainderLoop(this, min, max, Effect.empty$2()));
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/** @internal */
|
|
415
|
-
const takeRemainderLoop = (self, min, max, acc) => {
|
|
416
|
-
if (max < min) {
|
|
417
|
-
return Effect.succeed$1(acc);
|
|
418
|
-
}
|
|
419
|
-
return Effect.pipe(takeUpTo(self, max), Effect.flatMap(bs => {
|
|
420
|
-
const remaining = min - bs.length;
|
|
421
|
-
if (remaining === 1) {
|
|
422
|
-
return Effect.pipe(take$1(self), Effect.map(b => Effect.pipe(acc, Effect.appendAll(bs), Effect.append(b))));
|
|
423
|
-
}
|
|
424
|
-
if (remaining > 1) {
|
|
425
|
-
return Effect.pipe(take$1(self), Effect.flatMap(b => takeRemainderLoop(self, remaining - 1, max - bs.length - 1, Effect.pipe(acc, Effect.appendAll(bs), Effect.append(b)))));
|
|
426
|
-
}
|
|
427
|
-
return Effect.succeed$1(Effect.pipe(acc, Effect.appendAll(bs)));
|
|
428
|
-
}));
|
|
429
|
-
};
|
|
430
|
-
/** @internal */
|
|
431
|
-
const bounded$1 = requestedCapacity => Effect.pipe(Effect.sync(() => MutableQueue.bounded(requestedCapacity)), Effect.flatMap(queue => make$2(backingQueueFromMutableQueue(queue), backPressureStrategy())));
|
|
432
|
-
/** @internal */
|
|
433
|
-
const unbounded$1 = () => Effect.pipe(Effect.sync(() => MutableQueue.unbounded()), Effect.flatMap(queue => make$2(backingQueueFromMutableQueue(queue), droppingStrategy())));
|
|
434
|
-
/** @internal */
|
|
435
|
-
const unsafeMake = (queue, takers, shutdownHook, shutdownFlag, strategy) => {
|
|
436
|
-
return new QueueImpl(queue, takers, shutdownHook, shutdownFlag, strategy);
|
|
437
|
-
};
|
|
438
|
-
/** @internal */
|
|
439
|
-
const make$2 = (queue, strategy) => Effect.pipe(Effect.deferredMake(), Effect.map(deferred => unsafeMake(queue, MutableQueue.unbounded(), deferred, Effect.make(false), strategy)));
|
|
440
|
-
/** @internal */
|
|
441
|
-
class BackingQueueFromMutableQueue {
|
|
442
|
-
mutable;
|
|
443
|
-
[BackingQueueTypeId] = backingQueueVariance;
|
|
444
|
-
constructor(mutable) {
|
|
445
|
-
this.mutable = mutable;
|
|
446
|
-
}
|
|
447
|
-
poll(def) {
|
|
448
|
-
return MutableQueue.poll(this.mutable, def);
|
|
449
|
-
}
|
|
450
|
-
pollUpTo(limit) {
|
|
451
|
-
return MutableQueue.pollUpTo(this.mutable, limit);
|
|
452
|
-
}
|
|
453
|
-
offerAll(elements) {
|
|
454
|
-
return MutableQueue.offerAll(this.mutable, elements);
|
|
455
|
-
}
|
|
456
|
-
offer(element) {
|
|
457
|
-
return MutableQueue.offer(this.mutable, element);
|
|
458
|
-
}
|
|
459
|
-
capacity() {
|
|
460
|
-
return MutableQueue.capacity(this.mutable);
|
|
461
|
-
}
|
|
462
|
-
length() {
|
|
463
|
-
return MutableQueue.length(this.mutable);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
/** @internal */
|
|
467
|
-
const backingQueueFromMutableQueue = mutable => new BackingQueueFromMutableQueue(mutable);
|
|
468
|
-
/** @internal */
|
|
469
|
-
const size$1 = self => self.size;
|
|
470
|
-
/** @internal */
|
|
471
|
-
const isShutdown$1 = self => self.isShutdown;
|
|
472
|
-
/** @internal */
|
|
473
|
-
const shutdown$1 = self => self.shutdown;
|
|
474
|
-
/** @internal */
|
|
475
|
-
const offer$1 = /*#__PURE__*/Effect.dual(2, (self, value) => self.offer(value));
|
|
476
|
-
/** @internal */
|
|
477
|
-
const take$1 = self => self.take;
|
|
478
|
-
/** @internal */
|
|
479
|
-
const takeUpTo = /*#__PURE__*/Effect.dual(2, (self, max) => self.takeUpTo(max));
|
|
480
|
-
/** @internal */
|
|
481
|
-
const takeBetween$1 = /*#__PURE__*/Effect.dual(3, (self, min, max) => self.takeBetween(min, max));
|
|
482
|
-
// -----------------------------------------------------------------------------
|
|
483
|
-
// Strategy
|
|
484
|
-
// -----------------------------------------------------------------------------
|
|
485
|
-
/** @internal */
|
|
486
|
-
const backPressureStrategy = () => new BackPressureStrategy();
|
|
487
|
-
/** @internal */
|
|
488
|
-
const droppingStrategy = () => new DroppingStrategy();
|
|
489
|
-
/** @internal */
|
|
490
|
-
class BackPressureStrategy {
|
|
491
|
-
[QueueStrategyTypeId] = queueStrategyVariance;
|
|
492
|
-
putters = /*#__PURE__*/MutableQueue.unbounded();
|
|
493
|
-
surplusSize() {
|
|
494
|
-
return MutableQueue.length(this.putters);
|
|
495
|
-
}
|
|
496
|
-
onCompleteTakersWithEmptyQueue(takers) {
|
|
497
|
-
while (!MutableQueue.isEmpty(this.putters) && !MutableQueue.isEmpty(takers)) {
|
|
498
|
-
const taker = MutableQueue.poll(takers, void 0);
|
|
499
|
-
const putter = MutableQueue.poll(this.putters, void 0);
|
|
500
|
-
if (putter[2]) {
|
|
501
|
-
unsafeCompleteDeferred(putter[1], true);
|
|
502
|
-
}
|
|
503
|
-
unsafeCompleteDeferred(taker, putter[0]);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
get shutdown() {
|
|
507
|
-
return Effect.pipe(Effect.fiberId, Effect.flatMap(fiberId => Effect.pipe(Effect.sync(() => unsafePollAll(this.putters)), Effect.flatMap(putters => Effect.forEachConcurrentDiscard(putters, ([_, deferred, isLastItem]) => isLastItem ? Effect.pipe(Effect.deferredInterruptWith(deferred, fiberId), Effect.asVoid) : Effect.void_, false, false)))));
|
|
508
|
-
}
|
|
509
|
-
handleSurplus(iterable, queue, takers, isShutdown) {
|
|
510
|
-
return Effect.withFiberRuntime(state => {
|
|
511
|
-
const deferred = Effect.deferredUnsafeMake(state.id());
|
|
512
|
-
return Effect.pipe(Effect.suspend(() => {
|
|
513
|
-
this.unsafeOffer(iterable, deferred);
|
|
514
|
-
this.unsafeOnQueueEmptySpace(queue, takers);
|
|
515
|
-
unsafeCompleteTakers(this, queue, takers);
|
|
516
|
-
return Effect.get$2(isShutdown) ? Effect.interrupt$1 : Effect.deferredAwait(deferred);
|
|
517
|
-
}), Effect.onInterrupt(() => Effect.sync(() => this.unsafeRemove(deferred))));
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
unsafeOnQueueEmptySpace(queue, takers) {
|
|
521
|
-
let keepPolling = true;
|
|
522
|
-
while (keepPolling && (queue.capacity() === Number.POSITIVE_INFINITY || queue.length() < queue.capacity())) {
|
|
523
|
-
const putter = Effect.pipe(this.putters, MutableQueue.poll(MutableQueue.EmptyMutableQueue));
|
|
524
|
-
if (putter === MutableQueue.EmptyMutableQueue) {
|
|
525
|
-
keepPolling = false;
|
|
526
|
-
} else {
|
|
527
|
-
const offered = queue.offer(putter[0]);
|
|
528
|
-
if (offered && putter[2]) {
|
|
529
|
-
unsafeCompleteDeferred(putter[1], true);
|
|
530
|
-
} else if (!offered) {
|
|
531
|
-
unsafeOfferAll(this.putters, Effect.pipe(unsafePollAll(this.putters), Effect.prepend(putter)));
|
|
532
|
-
}
|
|
533
|
-
unsafeCompleteTakers(this, queue, takers);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
unsafeOffer(iterable, deferred) {
|
|
538
|
-
const stuff = Effect.fromIterable(iterable);
|
|
539
|
-
for (let i = 0; i < stuff.length; i++) {
|
|
540
|
-
const value = stuff[i];
|
|
541
|
-
if (i === stuff.length - 1) {
|
|
542
|
-
Effect.pipe(this.putters, MutableQueue.offer([value, deferred, true]));
|
|
543
|
-
} else {
|
|
544
|
-
Effect.pipe(this.putters, MutableQueue.offer([value, deferred, false]));
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
unsafeRemove(deferred) {
|
|
549
|
-
unsafeOfferAll(this.putters, Effect.pipe(unsafePollAll(this.putters), Effect.filter(([, _]) => _ !== deferred)));
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
/** @internal */
|
|
553
|
-
class DroppingStrategy {
|
|
554
|
-
[QueueStrategyTypeId] = queueStrategyVariance;
|
|
555
|
-
surplusSize() {
|
|
556
|
-
return 0;
|
|
557
|
-
}
|
|
558
|
-
get shutdown() {
|
|
559
|
-
return Effect.void_;
|
|
560
|
-
}
|
|
561
|
-
onCompleteTakersWithEmptyQueue() {}
|
|
562
|
-
handleSurplus(_iterable, _queue, _takers, _isShutdown) {
|
|
563
|
-
return Effect.succeed$1(false);
|
|
564
|
-
}
|
|
565
|
-
unsafeOnQueueEmptySpace(_queue, _takers) {
|
|
566
|
-
//
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
/** @internal */
|
|
570
|
-
const unsafeCompleteDeferred = (deferred, a) => {
|
|
571
|
-
return Effect.deferredUnsafeDone(deferred, Effect.succeed$1(a));
|
|
572
|
-
};
|
|
573
|
-
/** @internal */
|
|
574
|
-
const unsafeOfferAll = (queue, as) => {
|
|
575
|
-
return Effect.pipe(queue, MutableQueue.offerAll(as));
|
|
576
|
-
};
|
|
577
|
-
/** @internal */
|
|
578
|
-
const unsafePollAll = queue => {
|
|
579
|
-
return Effect.pipe(queue, MutableQueue.pollUpTo(Number.POSITIVE_INFINITY));
|
|
580
|
-
};
|
|
581
|
-
/** @internal */
|
|
582
|
-
const unsafePollN = (queue, max) => {
|
|
583
|
-
return Effect.pipe(queue, MutableQueue.pollUpTo(max));
|
|
584
|
-
};
|
|
585
|
-
/** @internal */
|
|
586
|
-
const unsafeRemove = (queue, a) => {
|
|
587
|
-
unsafeOfferAll(queue, Effect.pipe(unsafePollAll(queue), Effect.filter(b => a !== b)));
|
|
588
|
-
};
|
|
589
|
-
/** @internal */
|
|
590
|
-
const unsafeCompleteTakers = (strategy, queue, takers) => {
|
|
591
|
-
// Check both a taker and an item are in the queue, starting with the taker
|
|
592
|
-
let keepPolling = true;
|
|
593
|
-
while (keepPolling && queue.length() !== 0) {
|
|
594
|
-
const taker = Effect.pipe(takers, MutableQueue.poll(MutableQueue.EmptyMutableQueue));
|
|
595
|
-
if (taker !== MutableQueue.EmptyMutableQueue) {
|
|
596
|
-
const element = queue.poll(MutableQueue.EmptyMutableQueue);
|
|
597
|
-
if (element !== MutableQueue.EmptyMutableQueue) {
|
|
598
|
-
unsafeCompleteDeferred(taker, element);
|
|
599
|
-
strategy.unsafeOnQueueEmptySpace(queue, takers);
|
|
600
|
-
} else {
|
|
601
|
-
unsafeOfferAll(takers, Effect.pipe(unsafePollAll(takers), Effect.prepend(taker)));
|
|
602
|
-
}
|
|
603
|
-
keepPolling = true;
|
|
604
|
-
} else {
|
|
605
|
-
keepPolling = false;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
if (keepPolling && queue.length() === 0 && !MutableQueue.isEmpty(takers)) {
|
|
609
|
-
strategy.onCompleteTakersWithEmptyQueue(takers);
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
/**
|
|
614
|
-
* Makes a new bounded `Queue`. When the capacity of the queue is reached, any
|
|
615
|
-
* additional calls to `offer` will be suspended until there is more room in
|
|
616
|
-
* the queue.
|
|
617
|
-
*
|
|
618
|
-
* **Note**: When possible use only power of 2 capacities; this will provide
|
|
619
|
-
* better performance by utilising an optimised version of the underlying
|
|
620
|
-
* `RingBuffer`.
|
|
621
|
-
*
|
|
622
|
-
* @since 2.0.0
|
|
623
|
-
* @category constructors
|
|
624
|
-
*/
|
|
625
|
-
const bounded = bounded$1;
|
|
626
|
-
/**
|
|
627
|
-
* Creates a new unbounded `Queue`.
|
|
628
|
-
*
|
|
629
|
-
* @since 2.0.0
|
|
630
|
-
* @category constructors
|
|
631
|
-
*/
|
|
632
|
-
const unbounded = unbounded$1;
|
|
633
|
-
/**
|
|
634
|
-
* Retrieves the size of the queue, which is equal to the number of elements
|
|
635
|
-
* in the queue. This may be negative if fibers are suspended waiting for
|
|
636
|
-
* elements to be added to the queue.
|
|
637
|
-
*
|
|
638
|
-
* @since 2.0.0
|
|
639
|
-
* @category getters
|
|
640
|
-
*/
|
|
641
|
-
const size = size$1;
|
|
642
|
-
/**
|
|
643
|
-
* Returns `true` if `shutdown` has been called, otherwise returns `false`.
|
|
644
|
-
*
|
|
645
|
-
* @since 2.0.0
|
|
646
|
-
* @category getters
|
|
647
|
-
*/
|
|
648
|
-
const isShutdown = isShutdown$1;
|
|
649
|
-
/**
|
|
650
|
-
* Interrupts any fibers that are suspended on `offer` or `take`. Future calls
|
|
651
|
-
* to `offer*` and `take*` will be interrupted immediately.
|
|
652
|
-
*
|
|
653
|
-
* @since 2.0.0
|
|
654
|
-
* @category utils
|
|
655
|
-
*/
|
|
656
|
-
const shutdown = shutdown$1;
|
|
657
|
-
/**
|
|
658
|
-
* Places one value in the queue.
|
|
659
|
-
*
|
|
660
|
-
* @since 2.0.0
|
|
661
|
-
* @category utils
|
|
662
|
-
*/
|
|
663
|
-
const offer = offer$1;
|
|
664
|
-
/**
|
|
665
|
-
* Takes the oldest value in the queue. If the queue is empty, this will return
|
|
666
|
-
* a computation that resumes when an item has been added to the queue.
|
|
667
|
-
*
|
|
668
|
-
* @since 2.0.0
|
|
669
|
-
* @category utils
|
|
670
|
-
*/
|
|
671
|
-
const take = take$1;
|
|
672
|
-
/**
|
|
673
|
-
* Takes a number of elements from the queue between the specified minimum and
|
|
674
|
-
* maximum. If there are fewer than the minimum number of elements available,
|
|
675
|
-
* suspends until at least the minimum number of elements have been collected.
|
|
676
|
-
*
|
|
677
|
-
* @since 2.0.0
|
|
678
|
-
* @category utils
|
|
679
|
-
*/
|
|
680
|
-
const takeBetween = takeBetween$1;
|
|
681
|
-
|
|
682
|
-
/** @internal */
|
|
683
|
-
const OP_CONTINUE = "Continue";
|
|
684
|
-
/** @internal */
|
|
685
|
-
const OP_CLOSE = "Close";
|
|
686
|
-
/** @internal */
|
|
687
|
-
const OP_YIELD = "Yield";
|
|
688
|
-
|
|
689
|
-
/** @internal */
|
|
690
|
-
const ChildExecutorDecisionSymbolKey = "effect/ChannelChildExecutorDecision";
|
|
691
|
-
/** @internal */
|
|
692
|
-
const ChildExecutorDecisionTypeId = /*#__PURE__*/Symbol.for(ChildExecutorDecisionSymbolKey);
|
|
693
|
-
/** @internal */
|
|
694
|
-
const proto$7 = {
|
|
695
|
-
[ChildExecutorDecisionTypeId]: ChildExecutorDecisionTypeId
|
|
696
|
-
};
|
|
697
|
-
/** @internal */
|
|
698
|
-
const Continue = _ => {
|
|
699
|
-
const op = Object.create(proto$7);
|
|
700
|
-
op._tag = OP_CONTINUE;
|
|
701
|
-
return op;
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
/** @internal */
|
|
705
|
-
const OP_CONTINUATION_K = "ContinuationK";
|
|
706
|
-
/** @internal */
|
|
707
|
-
const OP_CONTINUATION_FINALIZER = "ContinuationFinalizer";
|
|
708
|
-
|
|
709
|
-
/** @internal */
|
|
710
|
-
const ContinuationTypeId = /*#__PURE__*/Symbol.for("effect/ChannelContinuation");
|
|
711
|
-
const continuationVariance = {
|
|
712
|
-
/* c8 ignore next */
|
|
713
|
-
_Env: _ => _,
|
|
714
|
-
/* c8 ignore next */
|
|
715
|
-
_InErr: _ => _,
|
|
716
|
-
/* c8 ignore next */
|
|
717
|
-
_InElem: _ => _,
|
|
718
|
-
/* c8 ignore next */
|
|
719
|
-
_InDone: _ => _,
|
|
720
|
-
/* c8 ignore next */
|
|
721
|
-
_OutErr: _ => _,
|
|
722
|
-
/* c8 ignore next */
|
|
723
|
-
_OutDone: _ => _,
|
|
724
|
-
/* c8 ignore next */
|
|
725
|
-
_OutErr2: _ => _,
|
|
726
|
-
/* c8 ignore next */
|
|
727
|
-
_OutElem: _ => _,
|
|
728
|
-
/* c8 ignore next */
|
|
729
|
-
_OutDone2: _ => _
|
|
730
|
-
};
|
|
731
|
-
/** @internal */
|
|
732
|
-
class ContinuationKImpl {
|
|
733
|
-
onSuccess;
|
|
734
|
-
onHalt;
|
|
735
|
-
_tag = OP_CONTINUATION_K;
|
|
736
|
-
[ContinuationTypeId] = continuationVariance;
|
|
737
|
-
constructor(onSuccess, onHalt) {
|
|
738
|
-
this.onSuccess = onSuccess;
|
|
739
|
-
this.onHalt = onHalt;
|
|
740
|
-
}
|
|
741
|
-
onExit(exit) {
|
|
742
|
-
return MutableQueue.isFailure(exit) ? this.onHalt(exit.cause) : this.onSuccess(exit.value);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
/** @internal */
|
|
746
|
-
class ContinuationFinalizerImpl {
|
|
747
|
-
finalizer;
|
|
748
|
-
_tag = OP_CONTINUATION_FINALIZER;
|
|
749
|
-
[ContinuationTypeId] = continuationVariance;
|
|
750
|
-
constructor(finalizer) {
|
|
751
|
-
this.finalizer = finalizer;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/** @internal */
|
|
756
|
-
const OP_PULL_AFTER_NEXT = "PullAfterNext";
|
|
757
|
-
/** @internal */
|
|
758
|
-
const OP_PULL_AFTER_ALL_ENQUEUED = "PullAfterAllEnqueued";
|
|
759
|
-
|
|
760
|
-
/** @internal */
|
|
761
|
-
const UpstreamPullStrategySymbolKey = "effect/ChannelUpstreamPullStrategy";
|
|
762
|
-
/** @internal */
|
|
763
|
-
const UpstreamPullStrategyTypeId = /*#__PURE__*/Symbol.for(UpstreamPullStrategySymbolKey);
|
|
764
|
-
const upstreamPullStrategyVariance = {
|
|
765
|
-
/* c8 ignore next */
|
|
766
|
-
_A: _ => _
|
|
767
|
-
};
|
|
768
|
-
/** @internal */
|
|
769
|
-
const proto$6 = {
|
|
770
|
-
[UpstreamPullStrategyTypeId]: upstreamPullStrategyVariance
|
|
771
|
-
};
|
|
772
|
-
/** @internal */
|
|
773
|
-
const PullAfterNext = emitSeparator => {
|
|
774
|
-
const op = Object.create(proto$6);
|
|
775
|
-
op._tag = OP_PULL_AFTER_NEXT;
|
|
776
|
-
op.emitSeparator = emitSeparator;
|
|
777
|
-
return op;
|
|
778
|
-
};
|
|
779
|
-
|
|
780
|
-
/** @internal */
|
|
781
|
-
const OP_BRACKET_OUT = "BracketOut";
|
|
782
|
-
/** @internal */
|
|
783
|
-
const OP_BRIDGE = "Bridge";
|
|
784
|
-
/** @internal */
|
|
785
|
-
const OP_CONCAT_ALL = "ConcatAll";
|
|
786
|
-
/** @internal */
|
|
787
|
-
const OP_EMIT$2 = "Emit";
|
|
788
|
-
/** @internal */
|
|
789
|
-
const OP_ENSURING = "Ensuring";
|
|
790
|
-
/** @internal */
|
|
791
|
-
const OP_FAIL = "Fail";
|
|
792
|
-
/** @internal */
|
|
793
|
-
const OP_FOLD = "Fold";
|
|
794
|
-
/** @internal */
|
|
795
|
-
const OP_FROM_EFFECT$1 = "FromEffect";
|
|
796
|
-
/** @internal */
|
|
797
|
-
const OP_PIPE_TO = "PipeTo";
|
|
798
|
-
/** @internal */
|
|
799
|
-
const OP_PROVIDE = "Provide";
|
|
800
|
-
/** @internal */
|
|
801
|
-
const OP_READ$1 = "Read";
|
|
802
|
-
/** @internal */
|
|
803
|
-
const OP_SUCCEED = "Succeed";
|
|
804
|
-
/** @internal */
|
|
805
|
-
const OP_SUCCEED_NOW = "SucceedNow";
|
|
806
|
-
/** @internal */
|
|
807
|
-
const OP_SUSPEND = "Suspend";
|
|
808
|
-
|
|
809
|
-
/** @internal */
|
|
810
|
-
const ChannelSymbolKey = "effect/Channel";
|
|
811
|
-
/** @internal */
|
|
812
|
-
const ChannelTypeId = /*#__PURE__*/Symbol.for(ChannelSymbolKey);
|
|
813
|
-
const channelVariance = {
|
|
814
|
-
/* c8 ignore next */
|
|
815
|
-
_Env: _ => _,
|
|
816
|
-
/* c8 ignore next */
|
|
817
|
-
_InErr: _ => _,
|
|
818
|
-
/* c8 ignore next */
|
|
819
|
-
_InElem: _ => _,
|
|
820
|
-
/* c8 ignore next */
|
|
821
|
-
_InDone: _ => _,
|
|
822
|
-
/* c8 ignore next */
|
|
823
|
-
_OutErr: _ => _,
|
|
824
|
-
/* c8 ignore next */
|
|
825
|
-
_OutElem: _ => _,
|
|
826
|
-
/* c8 ignore next */
|
|
827
|
-
_OutDone: _ => _
|
|
828
|
-
};
|
|
829
|
-
/** @internal */
|
|
830
|
-
const proto$5 = {
|
|
831
|
-
[ChannelTypeId]: channelVariance,
|
|
832
|
-
pipe() {
|
|
833
|
-
return Effect.pipeArguments(this, arguments);
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
/** @internal */
|
|
837
|
-
const isChannel = u => Effect.hasProperty(u, ChannelTypeId) || Effect.isEffect(u);
|
|
838
|
-
/** @internal */
|
|
839
|
-
const acquireReleaseOut = /*#__PURE__*/Effect.dual(2, (self, release) => {
|
|
840
|
-
const op = Object.create(proto$5);
|
|
841
|
-
op._tag = OP_BRACKET_OUT;
|
|
842
|
-
op.acquire = () => self;
|
|
843
|
-
op.finalizer = release;
|
|
844
|
-
return op;
|
|
845
|
-
});
|
|
846
|
-
/** @internal */
|
|
847
|
-
const concatAllWith = (channels, f, g) => {
|
|
848
|
-
const op = Object.create(proto$5);
|
|
849
|
-
op._tag = OP_CONCAT_ALL;
|
|
850
|
-
op.combineInners = f;
|
|
851
|
-
op.combineAll = g;
|
|
852
|
-
op.onPull = () => PullAfterNext(Effect.none());
|
|
853
|
-
op.onEmit = () => Continue;
|
|
854
|
-
op.value = () => channels;
|
|
855
|
-
op.k = Effect.identity;
|
|
856
|
-
return op;
|
|
857
|
-
};
|
|
858
|
-
/** @internal */
|
|
859
|
-
const concatMapWith = /*#__PURE__*/Effect.dual(4, (self, f, g, h) => {
|
|
860
|
-
const op = Object.create(proto$5);
|
|
861
|
-
op._tag = OP_CONCAT_ALL;
|
|
862
|
-
op.combineInners = g;
|
|
863
|
-
op.combineAll = h;
|
|
864
|
-
op.onPull = () => PullAfterNext(Effect.none());
|
|
865
|
-
op.onEmit = () => Continue;
|
|
866
|
-
op.value = () => self;
|
|
867
|
-
op.k = f;
|
|
868
|
-
return op;
|
|
869
|
-
});
|
|
870
|
-
/** @internal */
|
|
871
|
-
const embedInput = /*#__PURE__*/Effect.dual(2, (self, input) => {
|
|
872
|
-
const op = Object.create(proto$5);
|
|
873
|
-
op._tag = OP_BRIDGE;
|
|
874
|
-
op.input = input;
|
|
875
|
-
op.channel = self;
|
|
876
|
-
return op;
|
|
877
|
-
});
|
|
878
|
-
/** @internal */
|
|
879
|
-
const ensuringWith = /*#__PURE__*/Effect.dual(2, (self, finalizer) => {
|
|
880
|
-
const op = Object.create(proto$5);
|
|
881
|
-
op._tag = OP_ENSURING;
|
|
882
|
-
op.channel = self;
|
|
883
|
-
op.finalizer = finalizer;
|
|
884
|
-
return op;
|
|
885
|
-
});
|
|
886
|
-
/** @internal */
|
|
887
|
-
const fail = error => failCause$2(fail$1(error));
|
|
888
|
-
/** @internal */
|
|
889
|
-
const failCause$2 = cause => failCauseSync(() => cause);
|
|
890
|
-
/** @internal */
|
|
891
|
-
const failCauseSync = evaluate => {
|
|
892
|
-
const op = Object.create(proto$5);
|
|
893
|
-
op._tag = OP_FAIL;
|
|
894
|
-
op.error = evaluate;
|
|
895
|
-
return op;
|
|
896
|
-
};
|
|
897
|
-
/** @internal */
|
|
898
|
-
const flatMap$1 = /*#__PURE__*/Effect.dual(2, (self, f) => {
|
|
899
|
-
const op = Object.create(proto$5);
|
|
900
|
-
op._tag = OP_FOLD;
|
|
901
|
-
op.channel = self;
|
|
902
|
-
op.k = new ContinuationKImpl(f, failCause$2);
|
|
903
|
-
return op;
|
|
904
|
-
});
|
|
905
|
-
/** @internal */
|
|
906
|
-
const fromEffect$3 = effect => {
|
|
907
|
-
const op = Object.create(proto$5);
|
|
908
|
-
op._tag = OP_FROM_EFFECT$1;
|
|
909
|
-
op.effect = () => effect;
|
|
910
|
-
return op;
|
|
911
|
-
};
|
|
912
|
-
/** @internal */
|
|
913
|
-
const pipeTo = /*#__PURE__*/Effect.dual(2, (self, that) => {
|
|
914
|
-
const op = Object.create(proto$5);
|
|
915
|
-
op._tag = OP_PIPE_TO;
|
|
916
|
-
op.left = () => self;
|
|
917
|
-
op.right = () => that;
|
|
918
|
-
return op;
|
|
919
|
-
});
|
|
920
|
-
/** @internal */
|
|
921
|
-
const readWith = options => readWithCause({
|
|
922
|
-
onInput: options.onInput,
|
|
923
|
-
onFailure: cause => Effect.match$1(failureOrCause(cause), {
|
|
924
|
-
onLeft: options.onFailure,
|
|
925
|
-
onRight: failCause$2
|
|
926
|
-
}),
|
|
927
|
-
onDone: options.onDone
|
|
928
|
-
});
|
|
929
|
-
/** @internal */
|
|
930
|
-
const readWithCause = options => {
|
|
931
|
-
const op = Object.create(proto$5);
|
|
932
|
-
op._tag = OP_READ$1;
|
|
933
|
-
op.more = options.onInput;
|
|
934
|
-
op.done = new ContinuationKImpl(options.onDone, options.onFailure);
|
|
935
|
-
return op;
|
|
936
|
-
};
|
|
937
|
-
/** @internal */
|
|
938
|
-
const succeed = value => sync(() => value);
|
|
939
|
-
/** @internal */
|
|
940
|
-
const succeedNow = result => {
|
|
941
|
-
const op = Object.create(proto$5);
|
|
942
|
-
op._tag = OP_SUCCEED_NOW;
|
|
943
|
-
op.terminal = result;
|
|
944
|
-
return op;
|
|
945
|
-
};
|
|
946
|
-
/** @internal */
|
|
947
|
-
const suspend$1 = evaluate => {
|
|
948
|
-
const op = Object.create(proto$5);
|
|
949
|
-
op._tag = OP_SUSPEND;
|
|
950
|
-
op.channel = evaluate;
|
|
951
|
-
return op;
|
|
952
|
-
};
|
|
953
|
-
const sync = evaluate => {
|
|
954
|
-
const op = Object.create(proto$5);
|
|
955
|
-
op._tag = OP_SUCCEED;
|
|
956
|
-
op.evaluate = evaluate;
|
|
957
|
-
return op;
|
|
958
|
-
};
|
|
959
|
-
const void_ = /*#__PURE__*/succeedNow(void 0);
|
|
960
|
-
/** @internal */
|
|
961
|
-
const write = out => {
|
|
962
|
-
const op = Object.create(proto$5);
|
|
963
|
-
op._tag = OP_EMIT$2;
|
|
964
|
-
op.out = out;
|
|
965
|
-
return op;
|
|
966
|
-
};
|
|
967
|
-
|
|
968
|
-
/** @internal */
|
|
969
|
-
const OP_DONE$1 = "Done";
|
|
970
|
-
/** @internal */
|
|
971
|
-
const OP_EMIT$1 = "Emit";
|
|
972
|
-
/** @internal */
|
|
973
|
-
const OP_FROM_EFFECT = "FromEffect";
|
|
974
|
-
/** @internal */
|
|
975
|
-
const OP_READ = "Read";
|
|
976
|
-
|
|
977
|
-
/** @internal */
|
|
978
|
-
const ChannelStateTypeId = /*#__PURE__*/Symbol.for("effect/ChannelState");
|
|
979
|
-
const channelStateVariance = {
|
|
980
|
-
/* c8 ignore next */
|
|
981
|
-
_E: _ => _,
|
|
982
|
-
/* c8 ignore next */
|
|
983
|
-
_R: _ => _
|
|
984
|
-
};
|
|
985
|
-
/** @internal */
|
|
986
|
-
const proto$4 = {
|
|
987
|
-
[ChannelStateTypeId]: channelStateVariance
|
|
988
|
-
};
|
|
989
|
-
/** @internal */
|
|
990
|
-
const Done = () => {
|
|
991
|
-
const op = Object.create(proto$4);
|
|
992
|
-
op._tag = OP_DONE$1;
|
|
993
|
-
return op;
|
|
994
|
-
};
|
|
995
|
-
/** @internal */
|
|
996
|
-
const Emit$1 = () => {
|
|
997
|
-
const op = Object.create(proto$4);
|
|
998
|
-
op._tag = OP_EMIT$1;
|
|
999
|
-
return op;
|
|
1000
|
-
};
|
|
1001
|
-
/** @internal */
|
|
1002
|
-
const fromEffect$2 = effect => {
|
|
1003
|
-
const op = Object.create(proto$4);
|
|
1004
|
-
op._tag = OP_FROM_EFFECT;
|
|
1005
|
-
op.effect = effect;
|
|
1006
|
-
return op;
|
|
1007
|
-
};
|
|
1008
|
-
/** @internal */
|
|
1009
|
-
const Read = (upstream, onEffect, onEmit, onDone) => {
|
|
1010
|
-
const op = Object.create(proto$4);
|
|
1011
|
-
op._tag = OP_READ;
|
|
1012
|
-
op.upstream = upstream;
|
|
1013
|
-
op.onEffect = onEffect;
|
|
1014
|
-
op.onEmit = onEmit;
|
|
1015
|
-
op.onDone = onDone;
|
|
1016
|
-
return op;
|
|
1017
|
-
};
|
|
1018
|
-
/** @internal */
|
|
1019
|
-
const isFromEffect = self => self._tag === OP_FROM_EFFECT;
|
|
1020
|
-
/** @internal */
|
|
1021
|
-
const effect = self => isFromEffect(self) ? self.effect : Effect._void;
|
|
1022
|
-
/** @internal */
|
|
1023
|
-
const effectOrUndefinedIgnored = self => isFromEffect(self) ? Effect.ignore(self.effect) : undefined;
|
|
1024
|
-
|
|
1025
|
-
/** @internal */
|
|
1026
|
-
const OP_PULL_FROM_CHILD = "PullFromChild";
|
|
1027
|
-
/** @internal */
|
|
1028
|
-
const OP_PULL_FROM_UPSTREAM = "PullFromUpstream";
|
|
1029
|
-
/** @internal */
|
|
1030
|
-
const OP_DRAIN_CHILD_EXECUTORS = "DrainChildExecutors";
|
|
1031
|
-
/** @internal */
|
|
1032
|
-
const OP_EMIT = "Emit";
|
|
1033
|
-
/**
|
|
1034
|
-
* Execute the `childExecutor` and on each emitted value, decide what to do by
|
|
1035
|
-
* `onEmit`.
|
|
1036
|
-
*
|
|
1037
|
-
* @internal
|
|
1038
|
-
*/
|
|
1039
|
-
class PullFromChild {
|
|
1040
|
-
childExecutor;
|
|
1041
|
-
parentSubexecutor;
|
|
1042
|
-
onEmit;
|
|
1043
|
-
_tag = OP_PULL_FROM_CHILD;
|
|
1044
|
-
constructor(childExecutor, parentSubexecutor, onEmit) {
|
|
1045
|
-
this.childExecutor = childExecutor;
|
|
1046
|
-
this.parentSubexecutor = parentSubexecutor;
|
|
1047
|
-
this.onEmit = onEmit;
|
|
1048
|
-
}
|
|
1049
|
-
close(exit) {
|
|
1050
|
-
const fin1 = this.childExecutor.close(exit);
|
|
1051
|
-
const fin2 = this.parentSubexecutor.close(exit);
|
|
1052
|
-
if (fin1 !== undefined && fin2 !== undefined) {
|
|
1053
|
-
return Effect.zipWith(Effect.exit$1(fin1), Effect.exit$1(fin2), (exit1, exit2) => Effect.pipe(exit1, MutableQueue.zipRight(exit2)));
|
|
1054
|
-
} else if (fin1 !== undefined) {
|
|
1055
|
-
return fin1;
|
|
1056
|
-
} else if (fin2 !== undefined) {
|
|
1057
|
-
return fin2;
|
|
1058
|
-
} else {
|
|
1059
|
-
return undefined;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
enqueuePullFromChild(_child) {
|
|
1063
|
-
return this;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Execute `upstreamExecutor` and for each emitted element, spawn a child
|
|
1068
|
-
* channel and continue with processing it by `PullFromChild`.
|
|
1069
|
-
*
|
|
1070
|
-
* @internal
|
|
1071
|
-
*/
|
|
1072
|
-
class PullFromUpstream {
|
|
1073
|
-
upstreamExecutor;
|
|
1074
|
-
createChild;
|
|
1075
|
-
lastDone;
|
|
1076
|
-
activeChildExecutors;
|
|
1077
|
-
combineChildResults;
|
|
1078
|
-
combineWithChildResult;
|
|
1079
|
-
onPull;
|
|
1080
|
-
onEmit;
|
|
1081
|
-
_tag = OP_PULL_FROM_UPSTREAM;
|
|
1082
|
-
constructor(upstreamExecutor, createChild, lastDone, activeChildExecutors, combineChildResults, combineWithChildResult, onPull, onEmit) {
|
|
1083
|
-
this.upstreamExecutor = upstreamExecutor;
|
|
1084
|
-
this.createChild = createChild;
|
|
1085
|
-
this.lastDone = lastDone;
|
|
1086
|
-
this.activeChildExecutors = activeChildExecutors;
|
|
1087
|
-
this.combineChildResults = combineChildResults;
|
|
1088
|
-
this.combineWithChildResult = combineWithChildResult;
|
|
1089
|
-
this.onPull = onPull;
|
|
1090
|
-
this.onEmit = onEmit;
|
|
1091
|
-
}
|
|
1092
|
-
close(exit) {
|
|
1093
|
-
const fin1 = this.upstreamExecutor.close(exit);
|
|
1094
|
-
const fins = [...this.activeChildExecutors.map(child => child !== undefined ? child.childExecutor.close(exit) : undefined), fin1];
|
|
1095
|
-
const result = fins.reduce((acc, next) => {
|
|
1096
|
-
if (acc !== undefined && next !== undefined) {
|
|
1097
|
-
return Effect.zipWith(acc, Effect.exit$1(next), (exit1, exit2) => MutableQueue.zipRight(exit1, exit2));
|
|
1098
|
-
} else if (acc !== undefined) {
|
|
1099
|
-
return acc;
|
|
1100
|
-
} else if (next !== undefined) {
|
|
1101
|
-
return Effect.exit$1(next);
|
|
1102
|
-
} else {
|
|
1103
|
-
return undefined;
|
|
1104
|
-
}
|
|
1105
|
-
}, undefined);
|
|
1106
|
-
return result === undefined ? result : result;
|
|
1107
|
-
}
|
|
1108
|
-
enqueuePullFromChild(child) {
|
|
1109
|
-
return new PullFromUpstream(this.upstreamExecutor, this.createChild, this.lastDone, [...this.activeChildExecutors, child], this.combineChildResults, this.combineWithChildResult, this.onPull, this.onEmit);
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Transformed from `PullFromUpstream` when upstream has finished but there
|
|
1114
|
-
* are still active child executors.
|
|
1115
|
-
*
|
|
1116
|
-
* @internal
|
|
1117
|
-
*/
|
|
1118
|
-
class DrainChildExecutors {
|
|
1119
|
-
upstreamExecutor;
|
|
1120
|
-
lastDone;
|
|
1121
|
-
activeChildExecutors;
|
|
1122
|
-
upstreamDone;
|
|
1123
|
-
combineChildResults;
|
|
1124
|
-
combineWithChildResult;
|
|
1125
|
-
onPull;
|
|
1126
|
-
_tag = OP_DRAIN_CHILD_EXECUTORS;
|
|
1127
|
-
constructor(upstreamExecutor, lastDone, activeChildExecutors, upstreamDone, combineChildResults, combineWithChildResult, onPull) {
|
|
1128
|
-
this.upstreamExecutor = upstreamExecutor;
|
|
1129
|
-
this.lastDone = lastDone;
|
|
1130
|
-
this.activeChildExecutors = activeChildExecutors;
|
|
1131
|
-
this.upstreamDone = upstreamDone;
|
|
1132
|
-
this.combineChildResults = combineChildResults;
|
|
1133
|
-
this.combineWithChildResult = combineWithChildResult;
|
|
1134
|
-
this.onPull = onPull;
|
|
1135
|
-
}
|
|
1136
|
-
close(exit) {
|
|
1137
|
-
const fin1 = this.upstreamExecutor.close(exit);
|
|
1138
|
-
const fins = [...this.activeChildExecutors.map(child => child !== undefined ? child.childExecutor.close(exit) : undefined), fin1];
|
|
1139
|
-
const result = fins.reduce((acc, next) => {
|
|
1140
|
-
if (acc !== undefined && next !== undefined) {
|
|
1141
|
-
return Effect.zipWith(acc, Effect.exit$1(next), (exit1, exit2) => MutableQueue.zipRight(exit1, exit2));
|
|
1142
|
-
} else if (acc !== undefined) {
|
|
1143
|
-
return acc;
|
|
1144
|
-
} else if (next !== undefined) {
|
|
1145
|
-
return Effect.exit$1(next);
|
|
1146
|
-
} else {
|
|
1147
|
-
return undefined;
|
|
1148
|
-
}
|
|
1149
|
-
}, undefined);
|
|
1150
|
-
return result === undefined ? result : result;
|
|
1151
|
-
}
|
|
1152
|
-
enqueuePullFromChild(child) {
|
|
1153
|
-
return new DrainChildExecutors(this.upstreamExecutor, this.lastDone, [...this.activeChildExecutors, child], this.upstreamDone, this.combineChildResults, this.combineWithChildResult, this.onPull);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
/** @internal */
|
|
1157
|
-
class Emit {
|
|
1158
|
-
value;
|
|
1159
|
-
next;
|
|
1160
|
-
_tag = OP_EMIT;
|
|
1161
|
-
constructor(value, next) {
|
|
1162
|
-
this.value = value;
|
|
1163
|
-
this.next = next;
|
|
1164
|
-
}
|
|
1165
|
-
close(exit) {
|
|
1166
|
-
const result = this.next.close(exit);
|
|
1167
|
-
return result === undefined ? result : result;
|
|
1168
|
-
}
|
|
1169
|
-
enqueuePullFromChild(_child) {
|
|
1170
|
-
return this;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
/** @internal */
|
|
1175
|
-
const OP_PULLED = "Pulled";
|
|
1176
|
-
/** @internal */
|
|
1177
|
-
const OP_NO_UPSTREAM = "NoUpstream";
|
|
1178
|
-
|
|
1179
|
-
/** @internal */
|
|
1180
|
-
const UpstreamPullRequestSymbolKey = "effect/ChannelUpstreamPullRequest";
|
|
1181
|
-
/** @internal */
|
|
1182
|
-
const UpstreamPullRequestTypeId = /*#__PURE__*/Symbol.for(UpstreamPullRequestSymbolKey);
|
|
1183
|
-
const upstreamPullRequestVariance = {
|
|
1184
|
-
/* c8 ignore next */
|
|
1185
|
-
_A: _ => _
|
|
1186
|
-
};
|
|
1187
|
-
/** @internal */
|
|
1188
|
-
const proto$3 = {
|
|
1189
|
-
[UpstreamPullRequestTypeId]: upstreamPullRequestVariance
|
|
1190
|
-
};
|
|
1191
|
-
/** @internal */
|
|
1192
|
-
const Pulled = value => {
|
|
1193
|
-
const op = Object.create(proto$3);
|
|
1194
|
-
op._tag = OP_PULLED;
|
|
1195
|
-
op.value = value;
|
|
1196
|
-
return op;
|
|
1197
|
-
};
|
|
1198
|
-
/** @internal */
|
|
1199
|
-
const NoUpstream = activeDownstreamCount => {
|
|
1200
|
-
const op = Object.create(proto$3);
|
|
1201
|
-
op._tag = OP_NO_UPSTREAM;
|
|
1202
|
-
op.activeDownstreamCount = activeDownstreamCount;
|
|
1203
|
-
return op;
|
|
1204
|
-
};
|
|
1205
|
-
|
|
1206
|
-
/** @internal */
|
|
1207
|
-
class ChannelExecutor {
|
|
1208
|
-
_activeSubexecutor = undefined;
|
|
1209
|
-
_cancelled = undefined;
|
|
1210
|
-
_closeLastSubstream = undefined;
|
|
1211
|
-
_currentChannel;
|
|
1212
|
-
_done = undefined;
|
|
1213
|
-
_doneStack = [];
|
|
1214
|
-
_emitted = undefined;
|
|
1215
|
-
_executeCloseLastSubstream;
|
|
1216
|
-
_input = undefined;
|
|
1217
|
-
_inProgressFinalizer = undefined;
|
|
1218
|
-
_providedEnv;
|
|
1219
|
-
constructor(initialChannel, providedEnv, executeCloseLastSubstream) {
|
|
1220
|
-
this._currentChannel = initialChannel;
|
|
1221
|
-
this._executeCloseLastSubstream = executeCloseLastSubstream;
|
|
1222
|
-
this._providedEnv = providedEnv;
|
|
1223
|
-
}
|
|
1224
|
-
run() {
|
|
1225
|
-
let result = undefined;
|
|
1226
|
-
while (result === undefined) {
|
|
1227
|
-
if (this._cancelled !== undefined) {
|
|
1228
|
-
result = this.processCancellation();
|
|
1229
|
-
} else if (this._activeSubexecutor !== undefined) {
|
|
1230
|
-
result = this.runSubexecutor();
|
|
1231
|
-
} else {
|
|
1232
|
-
try {
|
|
1233
|
-
if (this._currentChannel === undefined) {
|
|
1234
|
-
result = Done();
|
|
1235
|
-
} else {
|
|
1236
|
-
if (Effect.isEffect(this._currentChannel)) {
|
|
1237
|
-
this._currentChannel = fromEffect$3(this._currentChannel);
|
|
1238
|
-
}
|
|
1239
|
-
switch (this._currentChannel._tag) {
|
|
1240
|
-
case OP_BRACKET_OUT:
|
|
1241
|
-
{
|
|
1242
|
-
result = this.runBracketOut(this._currentChannel);
|
|
1243
|
-
break;
|
|
1244
|
-
}
|
|
1245
|
-
case OP_BRIDGE:
|
|
1246
|
-
{
|
|
1247
|
-
const bridgeInput = this._currentChannel.input;
|
|
1248
|
-
// PipeTo(left, Bridge(queue, channel))
|
|
1249
|
-
// In a fiber: repeatedly run left and push its outputs to the queue
|
|
1250
|
-
// Add a finalizer to interrupt the fiber and close the executor
|
|
1251
|
-
this._currentChannel = this._currentChannel.channel;
|
|
1252
|
-
if (this._input !== undefined) {
|
|
1253
|
-
const inputExecutor = this._input;
|
|
1254
|
-
this._input = undefined;
|
|
1255
|
-
const drainer = () => Effect.flatMap$1(bridgeInput.awaitRead(), () => Effect.suspend$1(() => {
|
|
1256
|
-
const state = inputExecutor.run();
|
|
1257
|
-
switch (state._tag) {
|
|
1258
|
-
case OP_DONE$1:
|
|
1259
|
-
{
|
|
1260
|
-
return MutableQueue.match(inputExecutor.getDone(), {
|
|
1261
|
-
onFailure: cause => bridgeInput.error(cause),
|
|
1262
|
-
onSuccess: value => bridgeInput.done(value)
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
case OP_EMIT$1:
|
|
1266
|
-
{
|
|
1267
|
-
return Effect.flatMap$1(bridgeInput.emit(inputExecutor.getEmit()), () => drainer());
|
|
1268
|
-
}
|
|
1269
|
-
case OP_FROM_EFFECT:
|
|
1270
|
-
{
|
|
1271
|
-
return Effect.matchCauseEffect(state.effect, {
|
|
1272
|
-
onFailure: cause => bridgeInput.error(cause),
|
|
1273
|
-
onSuccess: () => drainer()
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
case OP_READ:
|
|
1277
|
-
{
|
|
1278
|
-
return readUpstream(state, () => drainer(), cause => bridgeInput.error(cause));
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
}));
|
|
1282
|
-
result = fromEffect$2(Effect.flatMap$1(Effect.forkDaemon(Effect.interruptible(drainer())), fiber => Effect.sync$1(() => this.addFinalizer(exit => Effect.flatMap$1(interrupt(fiber), () => Effect.suspend$1(() => {
|
|
1283
|
-
const effect = this.restorePipe(exit, inputExecutor);
|
|
1284
|
-
return effect !== undefined ? effect : Effect._void;
|
|
1285
|
-
}))))));
|
|
1286
|
-
}
|
|
1287
|
-
break;
|
|
1288
|
-
}
|
|
1289
|
-
case OP_CONCAT_ALL:
|
|
1290
|
-
{
|
|
1291
|
-
const executor = new ChannelExecutor(this._currentChannel.value(), this._providedEnv, effect => Effect.sync$1(() => {
|
|
1292
|
-
const prevLastClose = this._closeLastSubstream === undefined ? Effect._void : this._closeLastSubstream;
|
|
1293
|
-
this._closeLastSubstream = Effect.pipe(prevLastClose, Effect.zipRight$1(effect));
|
|
1294
|
-
}));
|
|
1295
|
-
executor._input = this._input;
|
|
1296
|
-
const channel = this._currentChannel;
|
|
1297
|
-
this._activeSubexecutor = new PullFromUpstream(executor, value => channel.k(value), undefined, [], (x, y) => channel.combineInners(x, y), (x, y) => channel.combineAll(x, y), request => channel.onPull(request), value => channel.onEmit(value));
|
|
1298
|
-
this._closeLastSubstream = undefined;
|
|
1299
|
-
this._currentChannel = undefined;
|
|
1300
|
-
break;
|
|
1301
|
-
}
|
|
1302
|
-
case OP_EMIT$2:
|
|
1303
|
-
{
|
|
1304
|
-
this._emitted = this._currentChannel.out;
|
|
1305
|
-
this._currentChannel = this._activeSubexecutor !== undefined ? undefined : void_;
|
|
1306
|
-
result = Emit$1();
|
|
1307
|
-
break;
|
|
1308
|
-
}
|
|
1309
|
-
case OP_ENSURING:
|
|
1310
|
-
{
|
|
1311
|
-
this.runEnsuring(this._currentChannel);
|
|
1312
|
-
break;
|
|
1313
|
-
}
|
|
1314
|
-
case OP_FAIL:
|
|
1315
|
-
{
|
|
1316
|
-
result = this.doneHalt(this._currentChannel.error());
|
|
1317
|
-
break;
|
|
1318
|
-
}
|
|
1319
|
-
case OP_FOLD:
|
|
1320
|
-
{
|
|
1321
|
-
this._doneStack.push(this._currentChannel.k);
|
|
1322
|
-
this._currentChannel = this._currentChannel.channel;
|
|
1323
|
-
break;
|
|
1324
|
-
}
|
|
1325
|
-
case OP_FROM_EFFECT$1:
|
|
1326
|
-
{
|
|
1327
|
-
const effect = this._providedEnv === undefined ? this._currentChannel.effect() : Effect.pipe(this._currentChannel.effect(), Effect.provide(this._providedEnv));
|
|
1328
|
-
result = fromEffect$2(Effect.matchCauseEffect(effect, {
|
|
1329
|
-
onFailure: cause => {
|
|
1330
|
-
const state = this.doneHalt(cause);
|
|
1331
|
-
return state !== undefined && isFromEffect(state) ? state.effect : Effect._void;
|
|
1332
|
-
},
|
|
1333
|
-
onSuccess: value => {
|
|
1334
|
-
const state = this.doneSucceed(value);
|
|
1335
|
-
return state !== undefined && isFromEffect(state) ? state.effect : Effect._void;
|
|
1336
|
-
}
|
|
1337
|
-
}));
|
|
1338
|
-
break;
|
|
1339
|
-
}
|
|
1340
|
-
case OP_PIPE_TO:
|
|
1341
|
-
{
|
|
1342
|
-
const previousInput = this._input;
|
|
1343
|
-
const leftExec = new ChannelExecutor(this._currentChannel.left(), this._providedEnv, effect => this._executeCloseLastSubstream(effect));
|
|
1344
|
-
leftExec._input = previousInput;
|
|
1345
|
-
this._input = leftExec;
|
|
1346
|
-
this.addFinalizer(exit => {
|
|
1347
|
-
const effect = this.restorePipe(exit, previousInput);
|
|
1348
|
-
return effect !== undefined ? effect : Effect._void;
|
|
1349
|
-
});
|
|
1350
|
-
this._currentChannel = this._currentChannel.right();
|
|
1351
|
-
break;
|
|
1352
|
-
}
|
|
1353
|
-
case OP_PROVIDE:
|
|
1354
|
-
{
|
|
1355
|
-
const previousEnv = this._providedEnv;
|
|
1356
|
-
this._providedEnv = this._currentChannel.context();
|
|
1357
|
-
this._currentChannel = this._currentChannel.inner;
|
|
1358
|
-
this.addFinalizer(() => Effect.sync$1(() => {
|
|
1359
|
-
this._providedEnv = previousEnv;
|
|
1360
|
-
}));
|
|
1361
|
-
break;
|
|
1362
|
-
}
|
|
1363
|
-
case OP_READ$1:
|
|
1364
|
-
{
|
|
1365
|
-
const read = this._currentChannel;
|
|
1366
|
-
result = Read(this._input, Effect.identity, emitted => {
|
|
1367
|
-
try {
|
|
1368
|
-
this._currentChannel = read.more(emitted);
|
|
1369
|
-
} catch (error) {
|
|
1370
|
-
this._currentChannel = read.done.onExit(MutableQueue.die(error));
|
|
1371
|
-
}
|
|
1372
|
-
return undefined;
|
|
1373
|
-
}, exit => {
|
|
1374
|
-
const onExit = exit => {
|
|
1375
|
-
return read.done.onExit(exit);
|
|
1376
|
-
};
|
|
1377
|
-
this._currentChannel = onExit(exit);
|
|
1378
|
-
return undefined;
|
|
1379
|
-
});
|
|
1380
|
-
break;
|
|
1381
|
-
}
|
|
1382
|
-
case OP_SUCCEED:
|
|
1383
|
-
{
|
|
1384
|
-
result = this.doneSucceed(this._currentChannel.evaluate());
|
|
1385
|
-
break;
|
|
1386
|
-
}
|
|
1387
|
-
case OP_SUCCEED_NOW:
|
|
1388
|
-
{
|
|
1389
|
-
result = this.doneSucceed(this._currentChannel.terminal);
|
|
1390
|
-
break;
|
|
1391
|
-
}
|
|
1392
|
-
case OP_SUSPEND:
|
|
1393
|
-
{
|
|
1394
|
-
this._currentChannel = this._currentChannel.channel();
|
|
1395
|
-
break;
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
this._currentChannel = failCause$2(die(error));
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
return result;
|
|
1405
|
-
}
|
|
1406
|
-
getDone() {
|
|
1407
|
-
return this._done;
|
|
1408
|
-
}
|
|
1409
|
-
getEmit() {
|
|
1410
|
-
return this._emitted;
|
|
1411
|
-
}
|
|
1412
|
-
cancelWith(exit) {
|
|
1413
|
-
this._cancelled = exit;
|
|
1414
|
-
}
|
|
1415
|
-
clearInProgressFinalizer() {
|
|
1416
|
-
this._inProgressFinalizer = undefined;
|
|
1417
|
-
}
|
|
1418
|
-
storeInProgressFinalizer(finalizer) {
|
|
1419
|
-
this._inProgressFinalizer = finalizer;
|
|
1420
|
-
}
|
|
1421
|
-
popAllFinalizers(exit) {
|
|
1422
|
-
const finalizers = [];
|
|
1423
|
-
let next = this._doneStack.pop();
|
|
1424
|
-
while (next) {
|
|
1425
|
-
if (next._tag === "ContinuationFinalizer") {
|
|
1426
|
-
finalizers.push(next.finalizer);
|
|
1427
|
-
}
|
|
1428
|
-
next = this._doneStack.pop();
|
|
1429
|
-
}
|
|
1430
|
-
const effect = finalizers.length === 0 ? Effect._void : runFinalizers(finalizers, exit);
|
|
1431
|
-
this.storeInProgressFinalizer(effect);
|
|
1432
|
-
return effect;
|
|
1433
|
-
}
|
|
1434
|
-
popNextFinalizers() {
|
|
1435
|
-
const builder = [];
|
|
1436
|
-
while (this._doneStack.length !== 0) {
|
|
1437
|
-
const cont = this._doneStack[this._doneStack.length - 1];
|
|
1438
|
-
if (cont._tag === OP_CONTINUATION_K) {
|
|
1439
|
-
return builder;
|
|
1440
|
-
}
|
|
1441
|
-
builder.push(cont);
|
|
1442
|
-
this._doneStack.pop();
|
|
1443
|
-
}
|
|
1444
|
-
return builder;
|
|
1445
|
-
}
|
|
1446
|
-
restorePipe(exit, prev) {
|
|
1447
|
-
const currInput = this._input;
|
|
1448
|
-
this._input = prev;
|
|
1449
|
-
if (currInput !== undefined) {
|
|
1450
|
-
const effect = currInput.close(exit);
|
|
1451
|
-
return effect;
|
|
1452
|
-
}
|
|
1453
|
-
return Effect._void;
|
|
1454
|
-
}
|
|
1455
|
-
close(exit) {
|
|
1456
|
-
let runInProgressFinalizers = undefined;
|
|
1457
|
-
const finalizer = this._inProgressFinalizer;
|
|
1458
|
-
if (finalizer !== undefined) {
|
|
1459
|
-
runInProgressFinalizers = Effect.pipe(finalizer, Effect.ensuring(Effect.sync$1(() => this.clearInProgressFinalizer())));
|
|
1460
|
-
}
|
|
1461
|
-
let closeSelf = undefined;
|
|
1462
|
-
const selfFinalizers = this.popAllFinalizers(exit);
|
|
1463
|
-
if (selfFinalizers !== undefined) {
|
|
1464
|
-
closeSelf = Effect.pipe(selfFinalizers, Effect.ensuring(Effect.sync$1(() => this.clearInProgressFinalizer())));
|
|
1465
|
-
}
|
|
1466
|
-
const closeSubexecutors = this._activeSubexecutor === undefined ? undefined : this._activeSubexecutor.close(exit);
|
|
1467
|
-
if (closeSubexecutors === undefined && runInProgressFinalizers === undefined && closeSelf === undefined) {
|
|
1468
|
-
return undefined;
|
|
1469
|
-
}
|
|
1470
|
-
return Effect.pipe(Effect.exit$1(ifNotNull(closeSubexecutors)), Effect.zip(Effect.exit$1(ifNotNull(runInProgressFinalizers))), Effect.zip(Effect.exit$1(ifNotNull(closeSelf))), Effect.map$2(([[exit1, exit2], exit3]) => Effect.pipe(exit1, MutableQueue.zipRight(exit2), MutableQueue.zipRight(exit3))), Effect.uninterruptible$1,
|
|
1471
|
-
// TODO: remove
|
|
1472
|
-
Effect.flatMap$1(exit => Effect.suspend$1(() => exit)));
|
|
1473
|
-
}
|
|
1474
|
-
doneSucceed(value) {
|
|
1475
|
-
if (this._doneStack.length === 0) {
|
|
1476
|
-
this._done = MutableQueue.succeed(value);
|
|
1477
|
-
this._currentChannel = undefined;
|
|
1478
|
-
return Done();
|
|
1479
|
-
}
|
|
1480
|
-
const head = this._doneStack[this._doneStack.length - 1];
|
|
1481
|
-
if (head._tag === OP_CONTINUATION_K) {
|
|
1482
|
-
this._doneStack.pop();
|
|
1483
|
-
this._currentChannel = head.onSuccess(value);
|
|
1484
|
-
return undefined;
|
|
1485
|
-
}
|
|
1486
|
-
const finalizers = this.popNextFinalizers();
|
|
1487
|
-
if (this._doneStack.length === 0) {
|
|
1488
|
-
this._doneStack = finalizers.reverse();
|
|
1489
|
-
this._done = MutableQueue.succeed(value);
|
|
1490
|
-
this._currentChannel = undefined;
|
|
1491
|
-
return Done();
|
|
1492
|
-
}
|
|
1493
|
-
const finalizerEffect = runFinalizers(finalizers.map(f => f.finalizer), MutableQueue.succeed(value));
|
|
1494
|
-
this.storeInProgressFinalizer(finalizerEffect);
|
|
1495
|
-
const effect = Effect.pipe(finalizerEffect, Effect.ensuring(Effect.sync$1(() => this.clearInProgressFinalizer())), Effect.uninterruptible$1, Effect.flatMap$1(() => Effect.sync$1(() => this.doneSucceed(value))));
|
|
1496
|
-
return fromEffect$2(effect);
|
|
1497
|
-
}
|
|
1498
|
-
doneHalt(cause) {
|
|
1499
|
-
if (this._doneStack.length === 0) {
|
|
1500
|
-
this._done = MutableQueue.failCause(cause);
|
|
1501
|
-
this._currentChannel = undefined;
|
|
1502
|
-
return Done();
|
|
1503
|
-
}
|
|
1504
|
-
const head = this._doneStack[this._doneStack.length - 1];
|
|
1505
|
-
if (head._tag === OP_CONTINUATION_K) {
|
|
1506
|
-
this._doneStack.pop();
|
|
1507
|
-
try {
|
|
1508
|
-
this._currentChannel = head.onHalt(cause);
|
|
1509
|
-
} catch (error) {
|
|
1510
|
-
this._currentChannel = failCause$2(die(error));
|
|
1511
|
-
}
|
|
1512
|
-
return undefined;
|
|
1513
|
-
}
|
|
1514
|
-
const finalizers = this.popNextFinalizers();
|
|
1515
|
-
if (this._doneStack.length === 0) {
|
|
1516
|
-
this._doneStack = finalizers.reverse();
|
|
1517
|
-
this._done = MutableQueue.failCause(cause);
|
|
1518
|
-
this._currentChannel = undefined;
|
|
1519
|
-
return Done();
|
|
1520
|
-
}
|
|
1521
|
-
const finalizerEffect = runFinalizers(finalizers.map(f => f.finalizer), MutableQueue.failCause(cause));
|
|
1522
|
-
this.storeInProgressFinalizer(finalizerEffect);
|
|
1523
|
-
const effect = Effect.pipe(finalizerEffect, Effect.ensuring(Effect.sync$1(() => this.clearInProgressFinalizer())), Effect.uninterruptible$1, Effect.flatMap$1(() => Effect.sync$1(() => this.doneHalt(cause))));
|
|
1524
|
-
return fromEffect$2(effect);
|
|
1525
|
-
}
|
|
1526
|
-
processCancellation() {
|
|
1527
|
-
this._currentChannel = undefined;
|
|
1528
|
-
this._done = this._cancelled;
|
|
1529
|
-
this._cancelled = undefined;
|
|
1530
|
-
return Done();
|
|
1531
|
-
}
|
|
1532
|
-
runBracketOut(bracketOut) {
|
|
1533
|
-
const effect = Effect.uninterruptible$1(Effect.matchCauseEffect(this.provide(bracketOut.acquire()), {
|
|
1534
|
-
onFailure: cause => Effect.sync$1(() => {
|
|
1535
|
-
this._currentChannel = failCause$2(cause);
|
|
1536
|
-
}),
|
|
1537
|
-
onSuccess: out => Effect.sync$1(() => {
|
|
1538
|
-
this.addFinalizer(exit => this.provide(bracketOut.finalizer(out, exit)));
|
|
1539
|
-
this._currentChannel = write(out);
|
|
1540
|
-
})
|
|
1541
|
-
}));
|
|
1542
|
-
return fromEffect$2(effect);
|
|
1543
|
-
}
|
|
1544
|
-
provide(effect) {
|
|
1545
|
-
if (this._providedEnv === undefined) {
|
|
1546
|
-
return effect;
|
|
1547
|
-
}
|
|
1548
|
-
return Effect.pipe(effect, Effect.provide(this._providedEnv));
|
|
1549
|
-
}
|
|
1550
|
-
runEnsuring(ensuring) {
|
|
1551
|
-
this.addFinalizer(ensuring.finalizer);
|
|
1552
|
-
this._currentChannel = ensuring.channel;
|
|
1553
|
-
}
|
|
1554
|
-
addFinalizer(f) {
|
|
1555
|
-
this._doneStack.push(new ContinuationFinalizerImpl(f));
|
|
1556
|
-
}
|
|
1557
|
-
runSubexecutor() {
|
|
1558
|
-
const subexecutor = this._activeSubexecutor;
|
|
1559
|
-
switch (subexecutor._tag) {
|
|
1560
|
-
case OP_PULL_FROM_CHILD:
|
|
1561
|
-
{
|
|
1562
|
-
return this.pullFromChild(subexecutor.childExecutor, subexecutor.parentSubexecutor, subexecutor.onEmit, subexecutor);
|
|
1563
|
-
}
|
|
1564
|
-
case OP_PULL_FROM_UPSTREAM:
|
|
1565
|
-
{
|
|
1566
|
-
return this.pullFromUpstream(subexecutor);
|
|
1567
|
-
}
|
|
1568
|
-
case OP_DRAIN_CHILD_EXECUTORS:
|
|
1569
|
-
{
|
|
1570
|
-
return this.drainChildExecutors(subexecutor);
|
|
1571
|
-
}
|
|
1572
|
-
case OP_EMIT:
|
|
1573
|
-
{
|
|
1574
|
-
this._emitted = subexecutor.value;
|
|
1575
|
-
this._activeSubexecutor = subexecutor.next;
|
|
1576
|
-
return Emit$1();
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
replaceSubexecutor(nextSubExec) {
|
|
1581
|
-
this._currentChannel = undefined;
|
|
1582
|
-
this._activeSubexecutor = nextSubExec;
|
|
1583
|
-
}
|
|
1584
|
-
finishWithExit(exit) {
|
|
1585
|
-
const state = MutableQueue.match(exit, {
|
|
1586
|
-
onFailure: cause => this.doneHalt(cause),
|
|
1587
|
-
onSuccess: value => this.doneSucceed(value)
|
|
1588
|
-
});
|
|
1589
|
-
this._activeSubexecutor = undefined;
|
|
1590
|
-
return state === undefined ? Effect._void : effect(state);
|
|
1591
|
-
}
|
|
1592
|
-
finishSubexecutorWithCloseEffect(subexecutorDone, ...closeFuncs) {
|
|
1593
|
-
this.addFinalizer(() => Effect.pipe(closeFuncs, Effect.forEach(closeFunc => Effect.pipe(Effect.sync$1(() => closeFunc(subexecutorDone)), Effect.flatMap$1(closeEffect => closeEffect !== undefined ? closeEffect : Effect._void)), {
|
|
1594
|
-
discard: true
|
|
1595
|
-
})));
|
|
1596
|
-
const state = Effect.pipe(subexecutorDone, MutableQueue.match({
|
|
1597
|
-
onFailure: cause => this.doneHalt(cause),
|
|
1598
|
-
onSuccess: value => this.doneSucceed(value)
|
|
1599
|
-
}));
|
|
1600
|
-
this._activeSubexecutor = undefined;
|
|
1601
|
-
return state;
|
|
1602
|
-
}
|
|
1603
|
-
applyUpstreamPullStrategy(upstreamFinished, queue, strategy) {
|
|
1604
|
-
switch (strategy._tag) {
|
|
1605
|
-
case OP_PULL_AFTER_NEXT:
|
|
1606
|
-
{
|
|
1607
|
-
const shouldPrepend = !upstreamFinished || queue.some(subexecutor => subexecutor !== undefined);
|
|
1608
|
-
return [strategy.emitSeparator, shouldPrepend ? [undefined, ...queue] : queue];
|
|
1609
|
-
}
|
|
1610
|
-
case OP_PULL_AFTER_ALL_ENQUEUED:
|
|
1611
|
-
{
|
|
1612
|
-
const shouldEnqueue = !upstreamFinished || queue.some(subexecutor => subexecutor !== undefined);
|
|
1613
|
-
return [strategy.emitSeparator, shouldEnqueue ? [...queue, undefined] : queue];
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
pullFromChild(childExecutor, parentSubexecutor, onEmitted, subexecutor) {
|
|
1618
|
-
return Read(childExecutor, Effect.identity, emitted => {
|
|
1619
|
-
const childExecutorDecision = onEmitted(emitted);
|
|
1620
|
-
switch (childExecutorDecision._tag) {
|
|
1621
|
-
case OP_CONTINUE:
|
|
1622
|
-
{
|
|
1623
|
-
break;
|
|
1624
|
-
}
|
|
1625
|
-
case OP_CLOSE:
|
|
1626
|
-
{
|
|
1627
|
-
this.finishWithDoneValue(childExecutor, parentSubexecutor, childExecutorDecision.value);
|
|
1628
|
-
break;
|
|
1629
|
-
}
|
|
1630
|
-
case OP_YIELD:
|
|
1631
|
-
{
|
|
1632
|
-
const modifiedParent = parentSubexecutor.enqueuePullFromChild(subexecutor);
|
|
1633
|
-
this.replaceSubexecutor(modifiedParent);
|
|
1634
|
-
break;
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
this._activeSubexecutor = new Emit(emitted, this._activeSubexecutor);
|
|
1638
|
-
return undefined;
|
|
1639
|
-
}, MutableQueue.match({
|
|
1640
|
-
onFailure: cause => {
|
|
1641
|
-
const state = this.handleSubexecutorFailure(childExecutor, parentSubexecutor, cause);
|
|
1642
|
-
return state === undefined ? undefined : effectOrUndefinedIgnored(state);
|
|
1643
|
-
},
|
|
1644
|
-
onSuccess: doneValue => {
|
|
1645
|
-
this.finishWithDoneValue(childExecutor, parentSubexecutor, doneValue);
|
|
1646
|
-
return undefined;
|
|
1647
|
-
}
|
|
1648
|
-
}));
|
|
1649
|
-
}
|
|
1650
|
-
finishWithDoneValue(childExecutor, parentSubexecutor, doneValue) {
|
|
1651
|
-
const subexecutor = parentSubexecutor;
|
|
1652
|
-
switch (subexecutor._tag) {
|
|
1653
|
-
case OP_PULL_FROM_UPSTREAM:
|
|
1654
|
-
{
|
|
1655
|
-
const modifiedParent = new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone !== undefined ? subexecutor.combineChildResults(subexecutor.lastDone, doneValue) : doneValue, subexecutor.activeChildExecutors, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit);
|
|
1656
|
-
this._closeLastSubstream = childExecutor.close(MutableQueue.succeed(doneValue));
|
|
1657
|
-
this.replaceSubexecutor(modifiedParent);
|
|
1658
|
-
break;
|
|
1659
|
-
}
|
|
1660
|
-
case OP_DRAIN_CHILD_EXECUTORS:
|
|
1661
|
-
{
|
|
1662
|
-
const modifiedParent = new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone !== undefined ? subexecutor.combineChildResults(subexecutor.lastDone, doneValue) : doneValue, subexecutor.activeChildExecutors, subexecutor.upstreamDone, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull);
|
|
1663
|
-
this._closeLastSubstream = childExecutor.close(MutableQueue.succeed(doneValue));
|
|
1664
|
-
this.replaceSubexecutor(modifiedParent);
|
|
1665
|
-
break;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
handleSubexecutorFailure(childExecutor, parentSubexecutor, cause) {
|
|
1670
|
-
return this.finishSubexecutorWithCloseEffect(MutableQueue.failCause(cause), exit => parentSubexecutor.close(exit), exit => childExecutor.close(exit));
|
|
1671
|
-
}
|
|
1672
|
-
pullFromUpstream(subexecutor) {
|
|
1673
|
-
if (subexecutor.activeChildExecutors.length === 0) {
|
|
1674
|
-
return this.performPullFromUpstream(subexecutor);
|
|
1675
|
-
}
|
|
1676
|
-
const activeChild = subexecutor.activeChildExecutors[0];
|
|
1677
|
-
const parentSubexecutor = new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone, subexecutor.activeChildExecutors.slice(1), subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit);
|
|
1678
|
-
if (activeChild === undefined) {
|
|
1679
|
-
return this.performPullFromUpstream(parentSubexecutor);
|
|
1680
|
-
}
|
|
1681
|
-
this.replaceSubexecutor(new PullFromChild(activeChild.childExecutor, parentSubexecutor, activeChild.onEmit));
|
|
1682
|
-
return undefined;
|
|
1683
|
-
}
|
|
1684
|
-
performPullFromUpstream(subexecutor) {
|
|
1685
|
-
return Read(subexecutor.upstreamExecutor, effect => {
|
|
1686
|
-
const closeLastSubstream = this._closeLastSubstream === undefined ? Effect._void : this._closeLastSubstream;
|
|
1687
|
-
this._closeLastSubstream = undefined;
|
|
1688
|
-
return Effect.pipe(this._executeCloseLastSubstream(closeLastSubstream), Effect.zipRight$1(effect));
|
|
1689
|
-
}, emitted => {
|
|
1690
|
-
if (this._closeLastSubstream !== undefined) {
|
|
1691
|
-
const closeLastSubstream = this._closeLastSubstream;
|
|
1692
|
-
this._closeLastSubstream = undefined;
|
|
1693
|
-
return Effect.pipe(this._executeCloseLastSubstream(closeLastSubstream), Effect.map$2(() => {
|
|
1694
|
-
const childExecutor = new ChannelExecutor(subexecutor.createChild(emitted), this._providedEnv, this._executeCloseLastSubstream);
|
|
1695
|
-
childExecutor._input = this._input;
|
|
1696
|
-
const [emitSeparator, updatedChildExecutors] = this.applyUpstreamPullStrategy(false, subexecutor.activeChildExecutors, subexecutor.onPull(Pulled(emitted)));
|
|
1697
|
-
this._activeSubexecutor = new PullFromChild(childExecutor, new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone, updatedChildExecutors, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit), subexecutor.onEmit);
|
|
1698
|
-
if (Effect.isSome(emitSeparator)) {
|
|
1699
|
-
this._activeSubexecutor = new Emit(emitSeparator.value, this._activeSubexecutor);
|
|
1700
|
-
}
|
|
1701
|
-
return undefined;
|
|
1702
|
-
}));
|
|
1703
|
-
}
|
|
1704
|
-
const childExecutor = new ChannelExecutor(subexecutor.createChild(emitted), this._providedEnv, this._executeCloseLastSubstream);
|
|
1705
|
-
childExecutor._input = this._input;
|
|
1706
|
-
const [emitSeparator, updatedChildExecutors] = this.applyUpstreamPullStrategy(false, subexecutor.activeChildExecutors, subexecutor.onPull(Pulled(emitted)));
|
|
1707
|
-
this._activeSubexecutor = new PullFromChild(childExecutor, new PullFromUpstream(subexecutor.upstreamExecutor, subexecutor.createChild, subexecutor.lastDone, updatedChildExecutors, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull, subexecutor.onEmit), subexecutor.onEmit);
|
|
1708
|
-
if (Effect.isSome(emitSeparator)) {
|
|
1709
|
-
this._activeSubexecutor = new Emit(emitSeparator.value, this._activeSubexecutor);
|
|
1710
|
-
}
|
|
1711
|
-
return undefined;
|
|
1712
|
-
}, exit => {
|
|
1713
|
-
if (subexecutor.activeChildExecutors.some(subexecutor => subexecutor !== undefined)) {
|
|
1714
|
-
const drain = new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone, [undefined, ...subexecutor.activeChildExecutors], subexecutor.upstreamExecutor.getDone(), subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull);
|
|
1715
|
-
if (this._closeLastSubstream !== undefined) {
|
|
1716
|
-
const closeLastSubstream = this._closeLastSubstream;
|
|
1717
|
-
this._closeLastSubstream = undefined;
|
|
1718
|
-
return Effect.pipe(this._executeCloseLastSubstream(closeLastSubstream), Effect.map$2(() => this.replaceSubexecutor(drain)));
|
|
1719
|
-
}
|
|
1720
|
-
this.replaceSubexecutor(drain);
|
|
1721
|
-
return undefined;
|
|
1722
|
-
}
|
|
1723
|
-
const closeLastSubstream = this._closeLastSubstream;
|
|
1724
|
-
const state = this.finishSubexecutorWithCloseEffect(Effect.pipe(exit, MutableQueue.map(a => subexecutor.combineWithChildResult(subexecutor.lastDone, a))), () => closeLastSubstream, exit => subexecutor.upstreamExecutor.close(exit));
|
|
1725
|
-
return state === undefined ? undefined :
|
|
1726
|
-
// NOTE: assuming finalizers cannot fail
|
|
1727
|
-
effectOrUndefinedIgnored(state);
|
|
1728
|
-
});
|
|
1729
|
-
}
|
|
1730
|
-
drainChildExecutors(subexecutor) {
|
|
1731
|
-
if (subexecutor.activeChildExecutors.length === 0) {
|
|
1732
|
-
const lastClose = this._closeLastSubstream;
|
|
1733
|
-
if (lastClose !== undefined) {
|
|
1734
|
-
this.addFinalizer(() => Effect.succeed(lastClose));
|
|
1735
|
-
}
|
|
1736
|
-
return this.finishSubexecutorWithCloseEffect(subexecutor.upstreamDone, () => lastClose, exit => subexecutor.upstreamExecutor.close(exit));
|
|
1737
|
-
}
|
|
1738
|
-
const activeChild = subexecutor.activeChildExecutors[0];
|
|
1739
|
-
const rest = subexecutor.activeChildExecutors.slice(1);
|
|
1740
|
-
if (activeChild === undefined) {
|
|
1741
|
-
const [emitSeparator, remainingExecutors] = this.applyUpstreamPullStrategy(true, rest, subexecutor.onPull(NoUpstream(rest.reduce((n, curr) => curr !== undefined ? n + 1 : n, 0))));
|
|
1742
|
-
this.replaceSubexecutor(new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone, remainingExecutors, subexecutor.upstreamDone, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull));
|
|
1743
|
-
if (Effect.isSome(emitSeparator)) {
|
|
1744
|
-
this._emitted = emitSeparator.value;
|
|
1745
|
-
return Emit$1();
|
|
1746
|
-
}
|
|
1747
|
-
return undefined;
|
|
1748
|
-
}
|
|
1749
|
-
const parentSubexecutor = new DrainChildExecutors(subexecutor.upstreamExecutor, subexecutor.lastDone, rest, subexecutor.upstreamDone, subexecutor.combineChildResults, subexecutor.combineWithChildResult, subexecutor.onPull);
|
|
1750
|
-
this.replaceSubexecutor(new PullFromChild(activeChild.childExecutor, parentSubexecutor, activeChild.onEmit));
|
|
1751
|
-
return undefined;
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
const ifNotNull = effect => effect !== undefined ? effect : Effect._void;
|
|
1755
|
-
const runFinalizers = (finalizers, exit) => {
|
|
1756
|
-
return Effect.pipe(Effect.forEach(finalizers, fin => Effect.exit$1(fin(exit))), Effect.map$2(exits => Effect.pipe(MutableQueue.all(exits), Effect.getOrElse(() => MutableQueue.void_))), Effect.flatMap$1(exit => Effect.suspend$1(() => exit)));
|
|
1757
|
-
};
|
|
1758
|
-
/**
|
|
1759
|
-
* @internal
|
|
1760
|
-
*/
|
|
1761
|
-
const readUpstream = (r, onSuccess, onFailure) => {
|
|
1762
|
-
const readStack = [r];
|
|
1763
|
-
const read = () => {
|
|
1764
|
-
const current = readStack.pop();
|
|
1765
|
-
if (current === undefined || current.upstream === undefined) {
|
|
1766
|
-
return Effect.dieMessage("Unexpected end of input for channel execution");
|
|
1767
|
-
}
|
|
1768
|
-
const state = current.upstream.run();
|
|
1769
|
-
switch (state._tag) {
|
|
1770
|
-
case OP_EMIT$1:
|
|
1771
|
-
{
|
|
1772
|
-
const emitEffect = current.onEmit(current.upstream.getEmit());
|
|
1773
|
-
if (readStack.length === 0) {
|
|
1774
|
-
if (emitEffect === undefined) {
|
|
1775
|
-
return Effect.suspend$1(onSuccess);
|
|
1776
|
-
}
|
|
1777
|
-
return Effect.pipe(emitEffect, Effect.matchCauseEffect({
|
|
1778
|
-
onFailure,
|
|
1779
|
-
onSuccess
|
|
1780
|
-
}));
|
|
1781
|
-
}
|
|
1782
|
-
if (emitEffect === undefined) {
|
|
1783
|
-
return Effect.suspend$1(() => read());
|
|
1784
|
-
}
|
|
1785
|
-
return Effect.pipe(emitEffect, Effect.matchCauseEffect({
|
|
1786
|
-
onFailure,
|
|
1787
|
-
onSuccess: () => read()
|
|
1788
|
-
}));
|
|
1789
|
-
}
|
|
1790
|
-
case OP_DONE$1:
|
|
1791
|
-
{
|
|
1792
|
-
const doneEffect = current.onDone(current.upstream.getDone());
|
|
1793
|
-
if (readStack.length === 0) {
|
|
1794
|
-
if (doneEffect === undefined) {
|
|
1795
|
-
return Effect.suspend$1(onSuccess);
|
|
1796
|
-
}
|
|
1797
|
-
return Effect.pipe(doneEffect, Effect.matchCauseEffect({
|
|
1798
|
-
onFailure,
|
|
1799
|
-
onSuccess
|
|
1800
|
-
}));
|
|
1801
|
-
}
|
|
1802
|
-
if (doneEffect === undefined) {
|
|
1803
|
-
return Effect.suspend$1(() => read());
|
|
1804
|
-
}
|
|
1805
|
-
return Effect.pipe(doneEffect, Effect.matchCauseEffect({
|
|
1806
|
-
onFailure,
|
|
1807
|
-
onSuccess: () => read()
|
|
1808
|
-
}));
|
|
1809
|
-
}
|
|
1810
|
-
case OP_FROM_EFFECT:
|
|
1811
|
-
{
|
|
1812
|
-
readStack.push(current);
|
|
1813
|
-
return Effect.pipe(current.onEffect(state.effect), Effect.catchAllCause(cause => Effect.suspend$1(() => {
|
|
1814
|
-
const doneEffect = current.onDone(MutableQueue.failCause(cause));
|
|
1815
|
-
return doneEffect === undefined ? Effect._void : doneEffect;
|
|
1816
|
-
})), Effect.matchCauseEffect({
|
|
1817
|
-
onFailure,
|
|
1818
|
-
onSuccess: () => read()
|
|
1819
|
-
}));
|
|
1820
|
-
}
|
|
1821
|
-
case OP_READ:
|
|
1822
|
-
{
|
|
1823
|
-
readStack.push(current);
|
|
1824
|
-
readStack.push(state);
|
|
1825
|
-
return Effect.suspend$1(() => read());
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
};
|
|
1829
|
-
return read();
|
|
1830
|
-
};
|
|
1831
|
-
/** @internal */
|
|
1832
|
-
const runIn = /*#__PURE__*/Effect.dual(2, (self, scope) => {
|
|
1833
|
-
const run = (channelDeferred, scopeDeferred, scope) => Effect.acquireUseRelease(Effect.sync$1(() => new ChannelExecutor(self, void 0, Effect.identity)), exec => Effect.suspend$1(() => runScopedInterpret(exec.run(), exec).pipe(Effect.intoDeferred(channelDeferred), Effect.zipRight$1(MutableQueue._await(channelDeferred)), Effect.zipLeft(MutableQueue._await(scopeDeferred)))), (exec, exit) => {
|
|
1834
|
-
const finalize = exec.close(exit);
|
|
1835
|
-
if (finalize === undefined) {
|
|
1836
|
-
return Effect._void;
|
|
1837
|
-
}
|
|
1838
|
-
return Effect.tapErrorCause(finalize, cause => Effect.addFinalizer(scope, Effect.failCause(cause)));
|
|
1839
|
-
});
|
|
1840
|
-
return Effect.uninterruptibleMask(restore => Effect.all$1([Effect.fork(scope, Effect.sequential), MutableQueue.make(), MutableQueue.make()]).pipe(Effect.flatMap$1(([child, channelDeferred, scopeDeferred]) => restore(run(channelDeferred, scopeDeferred, child)).pipe(Effect.forkIn(scope), Effect.flatMap$1(fiber => scope.addFinalizer(exit => {
|
|
1841
|
-
const interruptors$1 = MutableQueue.isFailure(exit) ? interruptors(exit.cause) : undefined;
|
|
1842
|
-
return MutableQueue.isDone(channelDeferred).pipe(Effect.flatMap$1(isDone => isDone ? MutableQueue.succeed$1(scopeDeferred, void 0).pipe(Effect.zipRight$1(_await(fiber)), Effect.zipRight$1(inheritAll(fiber))) : MutableQueue.succeed$1(scopeDeferred, void 0).pipe(Effect.zipRight$1(interruptors$1 && Effect.size$1(interruptors$1) > 0 ? interruptAs(fiber, Effect.combineAll(interruptors$1)) : interrupt(fiber)), Effect.zipRight$1(inheritAll(fiber)))));
|
|
1843
|
-
}).pipe(Effect.zipRight$1(restore(MutableQueue._await(channelDeferred)))))))));
|
|
1844
|
-
});
|
|
1845
|
-
/** @internal */
|
|
1846
|
-
const runScopedInterpret = (channelState, exec) => {
|
|
1847
|
-
const op = channelState;
|
|
1848
|
-
switch (op._tag) {
|
|
1849
|
-
case OP_FROM_EFFECT:
|
|
1850
|
-
{
|
|
1851
|
-
return Effect.pipe(op.effect, Effect.flatMap$1(() => runScopedInterpret(exec.run(), exec)));
|
|
1852
|
-
}
|
|
1853
|
-
case OP_EMIT$1:
|
|
1854
|
-
{
|
|
1855
|
-
// Can't really happen because Out <:< Nothing. So just skip ahead.
|
|
1856
|
-
return runScopedInterpret(exec.run(), exec);
|
|
1857
|
-
}
|
|
1858
|
-
case OP_DONE$1:
|
|
1859
|
-
{
|
|
1860
|
-
return Effect.suspend$1(() => exec.getDone());
|
|
1861
|
-
}
|
|
1862
|
-
case OP_READ:
|
|
1863
|
-
{
|
|
1864
|
-
return readUpstream(op, () => runScopedInterpret(exec.run(), exec), Effect.failCause);
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
};
|
|
1868
|
-
|
|
1869
|
-
/** @internal */
|
|
1870
|
-
const OP_DONE = "Done";
|
|
1871
|
-
/** @internal */
|
|
1872
|
-
const OP_AWAIT = "Await";
|
|
1873
|
-
|
|
1874
|
-
/** @internal */
|
|
1875
|
-
const MergeDecisionSymbolKey = "effect/ChannelMergeDecision";
|
|
1876
|
-
/** @internal */
|
|
1877
|
-
const MergeDecisionTypeId = /*#__PURE__*/Symbol.for(MergeDecisionSymbolKey);
|
|
1878
|
-
/** @internal */
|
|
1879
|
-
const proto$2 = {
|
|
1880
|
-
[MergeDecisionTypeId]: {
|
|
1881
|
-
_R: _ => _,
|
|
1882
|
-
_E0: _ => _,
|
|
1883
|
-
_Z0: _ => _,
|
|
1884
|
-
_E: _ => _,
|
|
1885
|
-
_Z: _ => _
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
/** @internal */
|
|
1889
|
-
const Await = f => {
|
|
1890
|
-
const op = Object.create(proto$2);
|
|
1891
|
-
op._tag = OP_AWAIT;
|
|
1892
|
-
op.f = f;
|
|
1893
|
-
return op;
|
|
1894
|
-
};
|
|
1895
|
-
|
|
1896
|
-
/** @internal */
|
|
1897
|
-
const OP_BOTH_RUNNING = "BothRunning";
|
|
1898
|
-
/** @internal */
|
|
1899
|
-
const OP_LEFT_DONE = "LeftDone";
|
|
1900
|
-
/** @internal */
|
|
1901
|
-
const OP_RIGHT_DONE = "RightDone";
|
|
1902
|
-
|
|
1903
|
-
/** @internal */
|
|
1904
|
-
const MergeStateSymbolKey = "effect/ChannelMergeState";
|
|
1905
|
-
/** @internal */
|
|
1906
|
-
const MergeStateTypeId = /*#__PURE__*/Symbol.for(MergeStateSymbolKey);
|
|
1907
|
-
/** @internal */
|
|
1908
|
-
const proto$1 = {
|
|
1909
|
-
[MergeStateTypeId]: MergeStateTypeId
|
|
1910
|
-
};
|
|
1911
|
-
/** @internal */
|
|
1912
|
-
const BothRunning = (left, right) => {
|
|
1913
|
-
const op = Object.create(proto$1);
|
|
1914
|
-
op._tag = OP_BOTH_RUNNING;
|
|
1915
|
-
op.left = left;
|
|
1916
|
-
op.right = right;
|
|
1917
|
-
return op;
|
|
1918
|
-
};
|
|
1919
|
-
/** @internal */
|
|
1920
|
-
const LeftDone = f => {
|
|
1921
|
-
const op = Object.create(proto$1);
|
|
1922
|
-
op._tag = OP_LEFT_DONE;
|
|
1923
|
-
op.f = f;
|
|
1924
|
-
return op;
|
|
1925
|
-
};
|
|
1926
|
-
/** @internal */
|
|
1927
|
-
const RightDone = f => {
|
|
1928
|
-
const op = Object.create(proto$1);
|
|
1929
|
-
op._tag = OP_RIGHT_DONE;
|
|
1930
|
-
op.f = f;
|
|
1931
|
-
return op;
|
|
1932
|
-
};
|
|
1933
|
-
|
|
1934
|
-
/** @internal */
|
|
1935
|
-
const OP_BACK_PRESSURE = "BackPressure";
|
|
1936
|
-
/** @internal */
|
|
1937
|
-
const OP_BUFFER_SLIDING = "BufferSliding";
|
|
1938
|
-
|
|
1939
|
-
/** @internal */
|
|
1940
|
-
const MergeStrategySymbolKey = "effect/ChannelMergeStrategy";
|
|
1941
|
-
/** @internal */
|
|
1942
|
-
const MergeStrategyTypeId = /*#__PURE__*/Symbol.for(MergeStrategySymbolKey);
|
|
1943
|
-
/** @internal */
|
|
1944
|
-
const proto = {
|
|
1945
|
-
[MergeStrategyTypeId]: MergeStrategyTypeId
|
|
1946
|
-
};
|
|
1947
|
-
/** @internal */
|
|
1948
|
-
const BackPressure = _ => {
|
|
1949
|
-
const op = Object.create(proto);
|
|
1950
|
-
op._tag = OP_BACK_PRESSURE;
|
|
1951
|
-
return op;
|
|
1952
|
-
};
|
|
1953
|
-
/** @internal */
|
|
1954
|
-
const BufferSliding = _ => {
|
|
1955
|
-
const op = Object.create(proto);
|
|
1956
|
-
op._tag = OP_BUFFER_SLIDING;
|
|
1957
|
-
return op;
|
|
1958
|
-
};
|
|
1959
|
-
/** @internal */
|
|
1960
|
-
const match = /*#__PURE__*/Effect.dual(2, (self, {
|
|
1961
|
-
onBackPressure,
|
|
1962
|
-
onBufferSliding
|
|
1963
|
-
}) => {
|
|
1964
|
-
switch (self._tag) {
|
|
1965
|
-
case OP_BACK_PRESSURE:
|
|
1966
|
-
{
|
|
1967
|
-
return onBackPressure();
|
|
1968
|
-
}
|
|
1969
|
-
case OP_BUFFER_SLIDING:
|
|
1970
|
-
{
|
|
1971
|
-
return onBufferSliding();
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
});
|
|
1975
|
-
|
|
1976
|
-
/** @internal */
|
|
1977
|
-
const OP_STATE_EMPTY = "Empty";
|
|
1978
|
-
/** @internal */
|
|
1979
|
-
const OP_STATE_EMIT = "Emit";
|
|
1980
|
-
/** @internal */
|
|
1981
|
-
const OP_STATE_ERROR = "Error";
|
|
1982
|
-
/** @internal */
|
|
1983
|
-
const OP_STATE_DONE = "Done";
|
|
1984
|
-
/** @internal */
|
|
1985
|
-
const stateEmpty = notifyProducer => ({
|
|
1986
|
-
_tag: OP_STATE_EMPTY,
|
|
1987
|
-
notifyProducer
|
|
1988
|
-
});
|
|
1989
|
-
/** @internal */
|
|
1990
|
-
const stateEmit = notifyConsumers => ({
|
|
1991
|
-
_tag: OP_STATE_EMIT,
|
|
1992
|
-
notifyConsumers
|
|
1993
|
-
});
|
|
1994
|
-
/** @internal */
|
|
1995
|
-
const stateError = cause => ({
|
|
1996
|
-
_tag: OP_STATE_ERROR,
|
|
1997
|
-
cause
|
|
1998
|
-
});
|
|
1999
|
-
/** @internal */
|
|
2000
|
-
const stateDone = done => ({
|
|
2001
|
-
_tag: OP_STATE_DONE,
|
|
2002
|
-
done
|
|
2003
|
-
});
|
|
2004
|
-
/** @internal */
|
|
2005
|
-
class SingleProducerAsyncInputImpl {
|
|
2006
|
-
ref;
|
|
2007
|
-
constructor(ref) {
|
|
2008
|
-
this.ref = ref;
|
|
2009
|
-
}
|
|
2010
|
-
awaitRead() {
|
|
2011
|
-
return Effect.flatten(modify(this.ref, state => state._tag === OP_STATE_EMPTY ? [MutableQueue._await(state.notifyProducer), state] : [Effect._void, state]));
|
|
2012
|
-
}
|
|
2013
|
-
get close() {
|
|
2014
|
-
return Effect.fiberIdWith(fiberId => this.error(interrupt$1(fiberId)));
|
|
2015
|
-
}
|
|
2016
|
-
done(value) {
|
|
2017
|
-
return Effect.flatten(modify(this.ref, state => {
|
|
2018
|
-
switch (state._tag) {
|
|
2019
|
-
case OP_STATE_EMPTY:
|
|
2020
|
-
{
|
|
2021
|
-
return [MutableQueue._await(state.notifyProducer), state];
|
|
2022
|
-
}
|
|
2023
|
-
case OP_STATE_EMIT:
|
|
2024
|
-
{
|
|
2025
|
-
return [Effect.forEach(state.notifyConsumers, deferred => MutableQueue.succeed$1(deferred, Effect.left(value)), {
|
|
2026
|
-
discard: true
|
|
2027
|
-
}), stateDone(value)];
|
|
2028
|
-
}
|
|
2029
|
-
case OP_STATE_ERROR:
|
|
2030
|
-
{
|
|
2031
|
-
return [Effect.interrupt$2, state];
|
|
2032
|
-
}
|
|
2033
|
-
case OP_STATE_DONE:
|
|
2034
|
-
{
|
|
2035
|
-
return [Effect.interrupt$2, state];
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
}));
|
|
2039
|
-
}
|
|
2040
|
-
emit(element) {
|
|
2041
|
-
return Effect.flatMap$1(MutableQueue.make(), deferred => Effect.flatten(modify(this.ref, state => {
|
|
2042
|
-
switch (state._tag) {
|
|
2043
|
-
case OP_STATE_EMPTY:
|
|
2044
|
-
{
|
|
2045
|
-
return [MutableQueue._await(state.notifyProducer), state];
|
|
2046
|
-
}
|
|
2047
|
-
case OP_STATE_EMIT:
|
|
2048
|
-
{
|
|
2049
|
-
const notifyConsumer = state.notifyConsumers[0];
|
|
2050
|
-
const notifyConsumers = state.notifyConsumers.slice(1);
|
|
2051
|
-
if (notifyConsumer !== undefined) {
|
|
2052
|
-
return [MutableQueue.succeed$1(notifyConsumer, Effect.right(element)), notifyConsumers.length === 0 ? stateEmpty(deferred) : stateEmit(notifyConsumers)];
|
|
2053
|
-
}
|
|
2054
|
-
throw new Error("Bug: Channel.SingleProducerAsyncInput.emit - Queue was empty! please report an issue at https://github.com/Effect-TS/effect/issues");
|
|
2055
|
-
}
|
|
2056
|
-
case OP_STATE_ERROR:
|
|
2057
|
-
{
|
|
2058
|
-
return [Effect.interrupt$2, state];
|
|
2059
|
-
}
|
|
2060
|
-
case OP_STATE_DONE:
|
|
2061
|
-
{
|
|
2062
|
-
return [Effect.interrupt$2, state];
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
})));
|
|
2066
|
-
}
|
|
2067
|
-
error(cause) {
|
|
2068
|
-
return Effect.flatten(modify(this.ref, state => {
|
|
2069
|
-
switch (state._tag) {
|
|
2070
|
-
case OP_STATE_EMPTY:
|
|
2071
|
-
{
|
|
2072
|
-
return [MutableQueue._await(state.notifyProducer), state];
|
|
2073
|
-
}
|
|
2074
|
-
case OP_STATE_EMIT:
|
|
2075
|
-
{
|
|
2076
|
-
return [Effect.forEach(state.notifyConsumers, deferred => MutableQueue.failCause$1(deferred, cause), {
|
|
2077
|
-
discard: true
|
|
2078
|
-
}), stateError(cause)];
|
|
2079
|
-
}
|
|
2080
|
-
case OP_STATE_ERROR:
|
|
2081
|
-
{
|
|
2082
|
-
return [Effect.interrupt$2, state];
|
|
2083
|
-
}
|
|
2084
|
-
case OP_STATE_DONE:
|
|
2085
|
-
{
|
|
2086
|
-
return [Effect.interrupt$2, state];
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
}));
|
|
2090
|
-
}
|
|
2091
|
-
get take() {
|
|
2092
|
-
return this.takeWith(cause => MutableQueue.failCause(map$2(cause, Effect.left)), elem => MutableQueue.succeed(elem), done => MutableQueue.fail(Effect.right(done)));
|
|
2093
|
-
}
|
|
2094
|
-
takeWith(onError, onElement, onDone) {
|
|
2095
|
-
return Effect.flatMap$1(MutableQueue.make(), deferred => Effect.flatten(modify(this.ref, state => {
|
|
2096
|
-
switch (state._tag) {
|
|
2097
|
-
case OP_STATE_EMPTY:
|
|
2098
|
-
{
|
|
2099
|
-
return [Effect.zipRight$1(MutableQueue.succeed$1(state.notifyProducer, void 0), Effect.matchCause(MutableQueue._await(deferred), {
|
|
2100
|
-
onFailure: onError,
|
|
2101
|
-
onSuccess: Effect.match$1({
|
|
2102
|
-
onLeft: onDone,
|
|
2103
|
-
onRight: onElement
|
|
2104
|
-
})
|
|
2105
|
-
})), stateEmit([deferred])];
|
|
2106
|
-
}
|
|
2107
|
-
case OP_STATE_EMIT:
|
|
2108
|
-
{
|
|
2109
|
-
return [Effect.matchCause(MutableQueue._await(deferred), {
|
|
2110
|
-
onFailure: onError,
|
|
2111
|
-
onSuccess: Effect.match$1({
|
|
2112
|
-
onLeft: onDone,
|
|
2113
|
-
onRight: onElement
|
|
2114
|
-
})
|
|
2115
|
-
}), stateEmit([...state.notifyConsumers, deferred])];
|
|
2116
|
-
}
|
|
2117
|
-
case OP_STATE_ERROR:
|
|
2118
|
-
{
|
|
2119
|
-
return [Effect.succeed(onError(state.cause)), state];
|
|
2120
|
-
}
|
|
2121
|
-
case OP_STATE_DONE:
|
|
2122
|
-
{
|
|
2123
|
-
return [Effect.succeed(onDone(state.done)), state];
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
})));
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2129
|
-
/** @internal */
|
|
2130
|
-
const make$1 = () => Effect.pipe(MutableQueue.make(), Effect.flatMap$1(deferred => make$3(stateEmpty(deferred))), Effect.map$2(ref => new SingleProducerAsyncInputImpl(ref)));
|
|
2131
|
-
|
|
2132
|
-
/** @internal */
|
|
2133
|
-
const concatMap = /*#__PURE__*/Effect.dual(2, (self, f) => concatMapWith(self, f, () => void 0, () => void 0));
|
|
2134
|
-
/** @internal */
|
|
2135
|
-
const drain$1 = self => {
|
|
2136
|
-
const drainer = readWithCause({
|
|
2137
|
-
onInput: () => drainer,
|
|
2138
|
-
onFailure: failCause$2,
|
|
2139
|
-
onDone: succeed
|
|
2140
|
-
});
|
|
2141
|
-
return pipeTo(self, drainer);
|
|
2142
|
-
};
|
|
2143
|
-
/** @internal */
|
|
2144
|
-
const ensuring$1 = /*#__PURE__*/Effect.dual(2, (self, finalizer) => ensuringWith(self, () => finalizer));
|
|
2145
|
-
/** @internal */
|
|
2146
|
-
const flatten$1 = self => flatMap$1(self, Effect.identity);
|
|
2147
|
-
/** @internal */
|
|
2148
|
-
const fromInput = input => unwrap(input.takeWith(failCause$2, elem => flatMap$1(write(elem), () => fromInput(input)), succeed));
|
|
2149
|
-
/** @internal */
|
|
2150
|
-
const identityChannel = () => readWith({
|
|
2151
|
-
onInput: input => flatMap$1(write(input), () => identityChannel()),
|
|
2152
|
-
onFailure: fail,
|
|
2153
|
-
onDone: succeedNow
|
|
2154
|
-
});
|
|
2155
|
-
/** @internal */
|
|
2156
|
-
const map$1 = /*#__PURE__*/Effect.dual(2, (self, f) => flatMap$1(self, a => sync(() => f(a))));
|
|
2157
|
-
/** @internal */
|
|
2158
|
-
const mapOut = /*#__PURE__*/Effect.dual(2, (self, f) => {
|
|
2159
|
-
const reader = readWith({
|
|
2160
|
-
onInput: outElem => flatMap$1(write(f(outElem)), () => reader),
|
|
2161
|
-
onFailure: fail,
|
|
2162
|
-
onDone: succeedNow
|
|
2163
|
-
});
|
|
2164
|
-
return pipeTo(self, reader);
|
|
2165
|
-
});
|
|
2166
|
-
/** @internal */
|
|
2167
|
-
const mapOutEffectPar = /*#__PURE__*/Effect.dual(3, (self, f, n) => unwrapScopedWith$1(scope => Effect.gen(function* () {
|
|
2168
|
-
const input = yield* make$1();
|
|
2169
|
-
const queueReader = fromInput(input);
|
|
2170
|
-
const queue = yield* bounded(n);
|
|
2171
|
-
yield* Effect.addFinalizer(scope, shutdown(queue));
|
|
2172
|
-
const errorSignal = yield* MutableQueue.make();
|
|
2173
|
-
const withPermits = n === Number.POSITIVE_INFINITY ? _ => Effect.identity : (yield* Effect.makeSemaphore(n)).withPermits;
|
|
2174
|
-
const pull = yield* queueReader.pipe(pipeTo(self), toPullIn(scope));
|
|
2175
|
-
yield* pull.pipe(Effect.matchCauseEffect({
|
|
2176
|
-
onFailure: cause => offer(queue, Effect.failCause(cause)),
|
|
2177
|
-
onSuccess: Effect.match$1({
|
|
2178
|
-
onLeft: outDone => Effect.zipRight$1(Effect.interruptible(withPermits(n)(Effect._void)), Effect.asVoid$1(offer(queue, Effect.succeed(Effect.left(outDone))))),
|
|
2179
|
-
onRight: outElem => Effect.gen(function* () {
|
|
2180
|
-
const deferred = yield* MutableQueue.make();
|
|
2181
|
-
const latch = yield* MutableQueue.make();
|
|
2182
|
-
yield* offer(queue, Effect.map$2(MutableQueue._await(deferred), Effect.right));
|
|
2183
|
-
yield* MutableQueue.succeed$1(latch, void 0).pipe(Effect.zipRight$1(Effect.uninterruptibleMask(restore => Effect.exit$1(restore(MutableQueue._await(errorSignal))).pipe(Effect.raceFirst(Effect.exit$1(restore(f(outElem)))), Effect.flatMap$1(Effect.identity))).pipe(Effect.tapErrorCause(cause => MutableQueue.failCause$1(errorSignal, cause)), Effect.intoDeferred(deferred))), withPermits(1), Effect.forkIn(scope));
|
|
2184
|
-
yield* MutableQueue._await(latch);
|
|
2185
|
-
})
|
|
2186
|
-
})
|
|
2187
|
-
}), Effect.forever, Effect.interruptible, Effect.forkIn(scope));
|
|
2188
|
-
const consumer = unwrap(Effect.matchCause(Effect.flatten(take(queue)), {
|
|
2189
|
-
onFailure: failCause$2,
|
|
2190
|
-
onSuccess: Effect.match$1({
|
|
2191
|
-
onLeft: succeedNow,
|
|
2192
|
-
onRight: outElem => flatMap$1(write(outElem), () => consumer)
|
|
2193
|
-
})
|
|
2194
|
-
}));
|
|
2195
|
-
return embedInput(consumer, input);
|
|
2196
|
-
})));
|
|
2197
|
-
/** @internal */
|
|
2198
|
-
const mergeAll = options => {
|
|
2199
|
-
return channels => mergeAllWith(options)(channels, Effect.constVoid);
|
|
2200
|
-
};
|
|
2201
|
-
/** @internal */
|
|
2202
|
-
const mergeAllWith = ({
|
|
2203
|
-
bufferSize = 16,
|
|
2204
|
-
concurrency,
|
|
2205
|
-
mergeStrategy = BackPressure()
|
|
2206
|
-
}) => (channels, f) => unwrapScopedWith$1(scope => Effect.gen(function* () {
|
|
2207
|
-
const concurrencyN = concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : concurrency;
|
|
2208
|
-
const input = yield* make$1();
|
|
2209
|
-
const queueReader = fromInput(input);
|
|
2210
|
-
const queue = yield* bounded(bufferSize);
|
|
2211
|
-
yield* Effect.addFinalizer(scope, shutdown(queue));
|
|
2212
|
-
const cancelers = yield* unbounded();
|
|
2213
|
-
yield* Effect.addFinalizer(scope, shutdown(cancelers));
|
|
2214
|
-
const lastDone = yield* make$3(Effect.none());
|
|
2215
|
-
const errorSignal = yield* MutableQueue.make();
|
|
2216
|
-
const withPermits = (yield* Effect.makeSemaphore(concurrencyN)).withPermits;
|
|
2217
|
-
const pull = yield* toPullIn(pipeTo(queueReader, channels), scope);
|
|
2218
|
-
function evaluatePull(pull) {
|
|
2219
|
-
return pull.pipe(Effect.flatMap$1(Effect.match$1({
|
|
2220
|
-
onLeft: done => Effect.succeed(Effect.some(done)),
|
|
2221
|
-
onRight: outElem => Effect.as(offer(queue, Effect.succeed(Effect.right(outElem))), Effect.none())
|
|
2222
|
-
})), Effect.repeat({
|
|
2223
|
-
until: _ => Effect.isSome(_)
|
|
2224
|
-
}), Effect.flatMap$1(outDone => update(lastDone, Effect.match({
|
|
2225
|
-
onNone: () => Effect.some(outDone.value),
|
|
2226
|
-
onSome: lastDone => Effect.some(f(lastDone, outDone.value))
|
|
2227
|
-
}))), Effect.catchAllCause(cause => isInterrupted(cause) ? Effect.failCause(cause) : offer(queue, Effect.failCause(cause)).pipe(Effect.zipRight$1(MutableQueue.succeed$1(errorSignal, void 0)), Effect.asVoid$1)));
|
|
2228
|
-
}
|
|
2229
|
-
yield* pull.pipe(Effect.matchCauseEffect({
|
|
2230
|
-
onFailure: cause => offer(queue, Effect.failCause(cause)).pipe(Effect.zipRight$1(Effect.succeed(false))),
|
|
2231
|
-
onSuccess: Effect.match$1({
|
|
2232
|
-
onLeft: outDone => Effect.raceWith(Effect.interruptible(MutableQueue._await(errorSignal)), Effect.interruptible(withPermits(concurrencyN)(Effect._void)), {
|
|
2233
|
-
onSelfDone: (_, permitAcquisition) => Effect.as(interrupt(permitAcquisition), false),
|
|
2234
|
-
onOtherDone: (_, failureAwait) => Effect.zipRight$1(interrupt(failureAwait), get(lastDone).pipe(Effect.flatMap$1(Effect.match({
|
|
2235
|
-
onNone: () => offer(queue, Effect.succeed(Effect.left(outDone))),
|
|
2236
|
-
onSome: lastDone => offer(queue, Effect.succeed(Effect.left(f(lastDone, outDone))))
|
|
2237
|
-
})), Effect.as(false)))
|
|
2238
|
-
}),
|
|
2239
|
-
onRight: channel => match(mergeStrategy, {
|
|
2240
|
-
onBackPressure: () => Effect.gen(function* () {
|
|
2241
|
-
const latch = yield* MutableQueue.make();
|
|
2242
|
-
const raceEffects = Effect.scopedWith(scope => toPullIn(pipeTo(queueReader, channel), scope).pipe(Effect.flatMap$1(pull => Effect.race(Effect.exit$1(evaluatePull(pull)), Effect.exit$1(Effect.interruptible(MutableQueue._await(errorSignal))))), Effect.flatMap$1(Effect.identity)));
|
|
2243
|
-
yield* MutableQueue.succeed$1(latch, void 0).pipe(Effect.zipRight$1(raceEffects), withPermits(1), Effect.forkIn(scope));
|
|
2244
|
-
yield* MutableQueue._await(latch);
|
|
2245
|
-
const errored = yield* MutableQueue.isDone(errorSignal);
|
|
2246
|
-
return !errored;
|
|
2247
|
-
}),
|
|
2248
|
-
onBufferSliding: () => Effect.gen(function* () {
|
|
2249
|
-
const canceler = yield* MutableQueue.make();
|
|
2250
|
-
const latch = yield* MutableQueue.make();
|
|
2251
|
-
const size$1 = yield* size(cancelers);
|
|
2252
|
-
yield* take(cancelers).pipe(Effect.flatMap$1(canceler => MutableQueue.succeed$1(canceler, void 0)), Effect.when$1(() => size$1 >= concurrencyN));
|
|
2253
|
-
yield* offer(cancelers, canceler);
|
|
2254
|
-
const raceEffects = Effect.scopedWith(scope => toPullIn(pipeTo(queueReader, channel), scope).pipe(Effect.flatMap$1(pull => Effect.exit$1(evaluatePull(pull)).pipe(Effect.race(Effect.exit$1(Effect.interruptible(MutableQueue._await(errorSignal)))), Effect.race(Effect.exit$1(Effect.interruptible(MutableQueue._await(canceler)))))), Effect.flatMap$1(Effect.identity)));
|
|
2255
|
-
yield* MutableQueue.succeed$1(latch, void 0).pipe(Effect.zipRight$1(raceEffects), withPermits(1), Effect.forkIn(scope));
|
|
2256
|
-
yield* MutableQueue._await(latch);
|
|
2257
|
-
const errored = yield* MutableQueue.isDone(errorSignal);
|
|
2258
|
-
return !errored;
|
|
2259
|
-
})
|
|
2260
|
-
})
|
|
2261
|
-
})
|
|
2262
|
-
}), Effect.repeat({
|
|
2263
|
-
while: _ => _
|
|
2264
|
-
}), Effect.forkIn(scope));
|
|
2265
|
-
const consumer = Effect.pipe(take(queue), Effect.flatten, Effect.matchCause({
|
|
2266
|
-
onFailure: failCause$2,
|
|
2267
|
-
onSuccess: Effect.match$1({
|
|
2268
|
-
onLeft: succeedNow,
|
|
2269
|
-
onRight: outElem => flatMap$1(write(outElem), () => consumer)
|
|
2270
|
-
})
|
|
2271
|
-
}), unwrap);
|
|
2272
|
-
return embedInput(consumer, input);
|
|
2273
|
-
}));
|
|
2274
|
-
/** @internal */
|
|
2275
|
-
const mergeMap = /*#__PURE__*/Effect.dual(3, (self, f, options) => mergeAll(options)(mapOut(self, f)));
|
|
2276
|
-
/** @internal */
|
|
2277
|
-
const mergeWith = /*#__PURE__*/Effect.dual(2, (self, options) => {
|
|
2278
|
-
function merge(scope) {
|
|
2279
|
-
return Effect.gen(function* () {
|
|
2280
|
-
const input = yield* make$1();
|
|
2281
|
-
const queueReader = fromInput(input);
|
|
2282
|
-
const pullL = yield* toPullIn(pipeTo(queueReader, self), scope);
|
|
2283
|
-
const pullR = yield* toPullIn(pipeTo(queueReader, options.other), scope);
|
|
2284
|
-
function handleSide(exit, fiber, pull) {
|
|
2285
|
-
return (done, both, single) => {
|
|
2286
|
-
function onDecision(decision) {
|
|
2287
|
-
const op = decision;
|
|
2288
|
-
if (op._tag === OP_DONE) {
|
|
2289
|
-
return Effect.succeed(fromEffect$3(Effect.zipRight$1(interrupt(fiber), op.effect)));
|
|
2290
|
-
}
|
|
2291
|
-
return Effect.map$2(_await(fiber), MutableQueue.match({
|
|
2292
|
-
onFailure: cause => fromEffect$3(op.f(MutableQueue.failCause(cause))),
|
|
2293
|
-
onSuccess: Effect.match$1({
|
|
2294
|
-
onLeft: done => fromEffect$3(op.f(MutableQueue.succeed(done))),
|
|
2295
|
-
onRight: elem => zipRight(write(elem), go(single(op.f)))
|
|
2296
|
-
})
|
|
2297
|
-
}));
|
|
2298
|
-
}
|
|
2299
|
-
return MutableQueue.match(exit, {
|
|
2300
|
-
onFailure: cause => onDecision(done(MutableQueue.failCause(cause))),
|
|
2301
|
-
onSuccess: Effect.match$1({
|
|
2302
|
-
onLeft: z => onDecision(done(MutableQueue.succeed(z))),
|
|
2303
|
-
onRight: elem => Effect.succeed(flatMap$1(write(elem), () => flatMap$1(fromEffect$3(Effect.forkIn(Effect.interruptible(pull), scope)), leftFiber => go(both(leftFiber, fiber)))))
|
|
2304
|
-
})
|
|
2305
|
-
});
|
|
2306
|
-
};
|
|
2307
|
-
}
|
|
2308
|
-
function go(state) {
|
|
2309
|
-
switch (state._tag) {
|
|
2310
|
-
case OP_BOTH_RUNNING:
|
|
2311
|
-
{
|
|
2312
|
-
const leftJoin = Effect.interruptible(join(state.left));
|
|
2313
|
-
const rightJoin = Effect.interruptible(join(state.right));
|
|
2314
|
-
return unwrap(Effect.raceWith(leftJoin, rightJoin, {
|
|
2315
|
-
onSelfDone: (leftExit, rf) => Effect.zipRight$1(interrupt(rf), handleSide(leftExit, state.right, pullL)(options.onSelfDone, BothRunning, f => LeftDone(f))),
|
|
2316
|
-
onOtherDone: (rightExit, lf) => Effect.zipRight$1(interrupt(lf), handleSide(rightExit, state.left, pullR)(options.onOtherDone, (left, right) => BothRunning(right, left), f => RightDone(f)))
|
|
2317
|
-
}));
|
|
2318
|
-
}
|
|
2319
|
-
case OP_LEFT_DONE:
|
|
2320
|
-
{
|
|
2321
|
-
return unwrap(Effect.map$2(Effect.exit$1(pullR), MutableQueue.match({
|
|
2322
|
-
onFailure: cause => fromEffect$3(state.f(MutableQueue.failCause(cause))),
|
|
2323
|
-
onSuccess: Effect.match$1({
|
|
2324
|
-
onLeft: done => fromEffect$3(state.f(MutableQueue.succeed(done))),
|
|
2325
|
-
onRight: elem => flatMap$1(write(elem), () => go(LeftDone(state.f)))
|
|
2326
|
-
})
|
|
2327
|
-
})));
|
|
2328
|
-
}
|
|
2329
|
-
case OP_RIGHT_DONE:
|
|
2330
|
-
{
|
|
2331
|
-
return unwrap(Effect.map$2(Effect.exit$1(pullL), MutableQueue.match({
|
|
2332
|
-
onFailure: cause => fromEffect$3(state.f(MutableQueue.failCause(cause))),
|
|
2333
|
-
onSuccess: Effect.match$1({
|
|
2334
|
-
onLeft: done => fromEffect$3(state.f(MutableQueue.succeed(done))),
|
|
2335
|
-
onRight: elem => flatMap$1(write(elem), () => go(RightDone(state.f)))
|
|
2336
|
-
})
|
|
2337
|
-
})));
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
return fromEffect$3(Effect.withFiberRuntime$1(parent => {
|
|
2342
|
-
const inherit = Effect.withFiberRuntime$1(state => {
|
|
2343
|
-
state.transferChildren(parent.scope());
|
|
2344
|
-
return Effect._void;
|
|
2345
|
-
});
|
|
2346
|
-
const leftFiber = Effect.interruptible(pullL).pipe(Effect.ensuring(inherit), Effect.forkIn(scope));
|
|
2347
|
-
const rightFiber = Effect.interruptible(pullR).pipe(Effect.ensuring(inherit), Effect.forkIn(scope));
|
|
2348
|
-
return Effect.zipWith(leftFiber, rightFiber, (left, right) => BothRunning(left, right));
|
|
2349
|
-
})).pipe(flatMap$1(go), embedInput(input));
|
|
2350
|
-
});
|
|
2351
|
-
}
|
|
2352
|
-
return unwrapScopedWith$1(merge);
|
|
2353
|
-
});
|
|
2354
|
-
/** @internal */
|
|
2355
|
-
const pipeToOrFail = /*#__PURE__*/Effect.dual(2, (self, that) => suspend$1(() => {
|
|
2356
|
-
let channelException = undefined;
|
|
2357
|
-
const reader = readWith({
|
|
2358
|
-
onInput: outElem => flatMap$1(write(outElem), () => reader),
|
|
2359
|
-
onFailure: outErr => {
|
|
2360
|
-
channelException = ChannelException(outErr);
|
|
2361
|
-
return failCause$2(die(channelException));
|
|
2362
|
-
},
|
|
2363
|
-
onDone: succeedNow
|
|
2364
|
-
});
|
|
2365
|
-
const writer = readWithCause({
|
|
2366
|
-
onInput: outElem => Effect.pipe(write(outElem), flatMap$1(() => writer)),
|
|
2367
|
-
onFailure: cause => isDieType(cause) && isChannelException(cause.defect) && Effect.equals(cause.defect, channelException) ? fail(cause.defect.error) : failCause$2(cause),
|
|
2368
|
-
onDone: succeedNow
|
|
2369
|
-
});
|
|
2370
|
-
return pipeTo(pipeTo(pipeTo(self, reader), that), writer);
|
|
2371
|
-
}));
|
|
2372
|
-
/** @internal */
|
|
2373
|
-
const run$1 = self => Effect.scopedWith(scope => runIn(self, scope));
|
|
2374
|
-
/** @internal */
|
|
2375
|
-
const runDrain$2 = self => run$1(drain$1(self));
|
|
2376
|
-
/** @internal */
|
|
2377
|
-
const scoped = effect => unwrap(Effect.uninterruptibleMask(restore => Effect.map$2(Effect.make$2(), scope => acquireReleaseOut(Effect.tapErrorCause(restore(Effect.extend(effect, scope)), cause => Effect.close(scope, MutableQueue.failCause(cause))), (_, exit) => Effect.close(scope, exit)))));
|
|
2378
|
-
/** @internal */
|
|
2379
|
-
const scopedWith$1 = f => unwrapScoped(Effect.map$2(Effect.scope, scope => flatMap$1(fromEffect$3(f(scope)), write)));
|
|
2380
|
-
/** @internal */
|
|
2381
|
-
const toPullIn = /*#__PURE__*/Effect.dual(2, (self, scope) => Effect.zip(Effect.sync$1(() => new ChannelExecutor(self, void 0, Effect.identity)), Effect.runtime()).pipe(Effect.tap(([executor, runtime]) => Effect.addFinalizerExit(scope, exit => {
|
|
2382
|
-
const finalizer = executor.close(exit);
|
|
2383
|
-
return finalizer !== undefined ? Effect.provide(finalizer, runtime) : Effect._void;
|
|
2384
|
-
})), Effect.uninterruptible$1, Effect.map$2(([executor]) => Effect.suspend$1(() => interpretToPull(executor.run(), executor)))));
|
|
2385
|
-
/** @internal */
|
|
2386
|
-
const interpretToPull = (channelState, exec) => {
|
|
2387
|
-
const state = channelState;
|
|
2388
|
-
switch (state._tag) {
|
|
2389
|
-
case OP_DONE$1:
|
|
2390
|
-
{
|
|
2391
|
-
return MutableQueue.match(exec.getDone(), {
|
|
2392
|
-
onFailure: Effect.failCause,
|
|
2393
|
-
onSuccess: done => Effect.succeed(Effect.left(done))
|
|
2394
|
-
});
|
|
2395
|
-
}
|
|
2396
|
-
case OP_EMIT$1:
|
|
2397
|
-
{
|
|
2398
|
-
return Effect.succeed(Effect.right(exec.getEmit()));
|
|
2399
|
-
}
|
|
2400
|
-
case OP_FROM_EFFECT:
|
|
2401
|
-
{
|
|
2402
|
-
return Effect.pipe(state.effect, Effect.flatMap$1(() => interpretToPull(exec.run(), exec)));
|
|
2403
|
-
}
|
|
2404
|
-
case OP_READ:
|
|
2405
|
-
{
|
|
2406
|
-
return readUpstream(state, () => interpretToPull(exec.run(), exec), cause => Effect.failCause(cause));
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
};
|
|
2410
|
-
/** @internal */
|
|
2411
|
-
const unwrap = channel => flatten$1(fromEffect$3(channel));
|
|
2412
|
-
/** @internal */
|
|
2413
|
-
const unwrapScoped = self => concatAllWith(scoped(self), (d, _) => d, (d, _) => d);
|
|
2414
|
-
/** @internal */
|
|
2415
|
-
const unwrapScopedWith$1 = f => concatAllWith(scopedWith$1(f), (d, _) => d, (d, _) => d);
|
|
2416
|
-
/** @internal */
|
|
2417
|
-
const writeChunk = outs => writeChunkWriter(0, outs.length, outs);
|
|
2418
|
-
/** @internal */
|
|
2419
|
-
const writeChunkWriter = (idx, len, chunk) => {
|
|
2420
|
-
return idx === len ? void_ : Effect.pipe(write(Effect.pipe(chunk, Effect.unsafeGet(idx))), flatMap$1(() => writeChunkWriter(idx + 1, len, chunk)));
|
|
2421
|
-
};
|
|
2422
|
-
/** @internal */
|
|
2423
|
-
const zip = /*#__PURE__*/Effect.dual(args => isChannel(args[1]), (self, that, options) => options?.concurrent ? mergeWith(self, {
|
|
2424
|
-
other: that,
|
|
2425
|
-
onSelfDone: exit1 => Await(exit2 => Effect.suspend$1(() => MutableQueue.zip(exit1, exit2))),
|
|
2426
|
-
onOtherDone: exit2 => Await(exit1 => Effect.suspend$1(() => MutableQueue.zip(exit1, exit2)))
|
|
2427
|
-
}) : flatMap$1(self, a => map$1(that, b => [a, b])));
|
|
2428
|
-
/** @internal */
|
|
2429
|
-
const zipRight = /*#__PURE__*/Effect.dual(args => isChannel(args[1]), (self, that, options) => options?.concurrent ? map$1(zip(self, that, {
|
|
2430
|
-
concurrent: true
|
|
2431
|
-
}), tuple => tuple[1]) : flatMap$1(self, () => that));
|
|
2432
|
-
/** @internal */
|
|
2433
|
-
const ChannelExceptionTypeId = /*#__PURE__*/Symbol.for("effect/Channel/ChannelException");
|
|
2434
|
-
/** @internal */
|
|
2435
|
-
const ChannelException = error => ({
|
|
2436
|
-
_tag: "ChannelException",
|
|
2437
|
-
[ChannelExceptionTypeId]: ChannelExceptionTypeId,
|
|
2438
|
-
error
|
|
2439
|
-
});
|
|
2440
|
-
/** @internal */
|
|
2441
|
-
const isChannelException = u => Effect.hasProperty(u, ChannelExceptionTypeId);
|
|
2442
|
-
|
|
2443
|
-
/** @internal */
|
|
2444
|
-
const SinkTypeId = /*#__PURE__*/Symbol.for("effect/Sink");
|
|
2445
|
-
const sinkVariance = {
|
|
2446
|
-
/* c8 ignore next */
|
|
2447
|
-
_A: _ => _,
|
|
2448
|
-
/* c8 ignore next */
|
|
2449
|
-
_In: _ => _,
|
|
2450
|
-
/* c8 ignore next */
|
|
2451
|
-
_L: _ => _,
|
|
2452
|
-
/* c8 ignore next */
|
|
2453
|
-
_E: _ => _,
|
|
2454
|
-
/* c8 ignore next */
|
|
2455
|
-
_R: _ => _
|
|
2456
|
-
};
|
|
2457
|
-
/** @internal */
|
|
2458
|
-
class SinkImpl {
|
|
2459
|
-
channel;
|
|
2460
|
-
[SinkTypeId] = sinkVariance;
|
|
2461
|
-
constructor(channel) {
|
|
2462
|
-
this.channel = channel;
|
|
2463
|
-
}
|
|
2464
|
-
pipe() {
|
|
2465
|
-
return Effect.pipeArguments(this, arguments);
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
/** @internal */
|
|
2469
|
-
const drain = /*#__PURE__*/new SinkImpl(/*#__PURE__*/drain$1(/*#__PURE__*/identityChannel()));
|
|
2470
|
-
/** @internal */
|
|
2471
|
-
const fromEffect$1 = effect => new SinkImpl(fromEffect$3(effect));
|
|
2472
|
-
/** @internal */
|
|
2473
|
-
const toChannel$1 = self => Effect.isEffect(self) ? toChannel$1(fromEffect$1(self)) : self.channel;
|
|
2474
|
-
|
|
2475
|
-
/** @internal */
|
|
2476
|
-
const TakeSymbolKey = "effect/Take";
|
|
2477
|
-
/** @internal */
|
|
2478
|
-
const TakeTypeId = /*#__PURE__*/Symbol.for(TakeSymbolKey);
|
|
2479
|
-
const takeVariance = {
|
|
2480
|
-
/* c8 ignore next */
|
|
2481
|
-
_A: _ => _,
|
|
2482
|
-
/* c8 ignore next */
|
|
2483
|
-
_E: _ => _
|
|
2484
|
-
};
|
|
2485
|
-
/** @internal */
|
|
2486
|
-
class TakeImpl {
|
|
2487
|
-
exit;
|
|
2488
|
-
[TakeTypeId] = takeVariance;
|
|
2489
|
-
constructor(exit) {
|
|
2490
|
-
this.exit = exit;
|
|
2491
|
-
}
|
|
2492
|
-
pipe() {
|
|
2493
|
-
return Effect.pipeArguments(this, arguments);
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
/** @internal */
|
|
2497
|
-
const chunk = chunk => new TakeImpl(MutableQueue.succeed(chunk));
|
|
2498
|
-
/** @internal */
|
|
2499
|
-
const end$1 = /*#__PURE__*/new TakeImpl(/*#__PURE__*/MutableQueue.fail(/*#__PURE__*/Effect.none()));
|
|
2500
|
-
/** @internal */
|
|
2501
|
-
const failCause$1 = cause => new TakeImpl(MutableQueue.failCause(Effect.pipe(cause, map$2(Effect.some))));
|
|
2502
|
-
/** @internal */
|
|
2503
|
-
const of = value => new TakeImpl(MutableQueue.succeed(Effect.of(value)));
|
|
2504
|
-
|
|
2505
|
-
/** @internal */
|
|
2506
|
-
const end = () => Effect.fail$1(Effect.none());
|
|
2507
|
-
/** @internal */
|
|
2508
|
-
const failCause = cause => Effect.mapError(Effect.failCause(cause), Effect.some);
|
|
2509
|
-
|
|
2510
|
-
/** @internal */
|
|
2511
|
-
const StreamSymbolKey = "effect/Stream";
|
|
2512
|
-
/** @internal */
|
|
2513
|
-
const StreamTypeId = /*#__PURE__*/Symbol.for(StreamSymbolKey);
|
|
2514
|
-
/** @internal */
|
|
2515
|
-
const streamVariance = {
|
|
2516
|
-
_R: _ => _,
|
|
2517
|
-
_E: _ => _,
|
|
2518
|
-
_A: _ => _
|
|
2519
|
-
};
|
|
2520
|
-
/** @internal */
|
|
2521
|
-
class StreamImpl {
|
|
2522
|
-
channel;
|
|
2523
|
-
[StreamTypeId] = streamVariance;
|
|
2524
|
-
constructor(channel) {
|
|
2525
|
-
this.channel = channel;
|
|
2526
|
-
}
|
|
2527
|
-
pipe() {
|
|
2528
|
-
return Effect.pipeArguments(this, arguments);
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
/** @internal */
|
|
2532
|
-
const isStream = u => Effect.hasProperty(u, StreamTypeId) || Effect.isEffect(u);
|
|
2533
|
-
/** @internal */
|
|
2534
|
-
const DefaultChunkSize = 4096;
|
|
2535
|
-
/** @internal */
|
|
2536
|
-
const ensuring = /*#__PURE__*/Effect.dual(2, (self, finalizer) => new StreamImpl(Effect.pipe(toChannel(self), ensuring$1(finalizer))));
|
|
2537
|
-
/** @internal */
|
|
2538
|
-
const flatMap = /*#__PURE__*/Effect.dual(args => isStream(args[0]), (self, f, options) => {
|
|
2539
|
-
const bufferSize = options?.bufferSize ?? 16;
|
|
2540
|
-
if (options?.switch) {
|
|
2541
|
-
return matchConcurrency(options?.concurrency, () => flatMapParSwitchBuffer(self, 1, bufferSize, f), n => flatMapParSwitchBuffer(self, n, bufferSize, f));
|
|
2542
|
-
}
|
|
2543
|
-
return matchConcurrency(options?.concurrency, () => new StreamImpl(concatMap(toChannel(self), as => Effect.pipe(as, Effect.map$3(a => toChannel(f(a))), Effect.reduce(void_, (left, right) => Effect.pipe(left, zipRight(right)))))), _ => new StreamImpl(Effect.pipe(toChannel(self), concatMap(writeChunk), mergeMap(out => toChannel(f(out)), options))));
|
|
2544
|
-
});
|
|
2545
|
-
/** @internal */
|
|
2546
|
-
const matchConcurrency = (concurrency, sequential, bounded) => {
|
|
2547
|
-
switch (concurrency) {
|
|
2548
|
-
case undefined:
|
|
2549
|
-
return sequential();
|
|
2550
|
-
case "unbounded":
|
|
2551
|
-
return bounded(Number.MAX_SAFE_INTEGER);
|
|
2552
|
-
default:
|
|
2553
|
-
return concurrency > 1 ? bounded(concurrency) : sequential();
|
|
2554
|
-
}
|
|
2555
|
-
};
|
|
2556
|
-
const flatMapParSwitchBuffer = /*#__PURE__*/Effect.dual(4, (self, n, bufferSize, f) => new StreamImpl(Effect.pipe(toChannel(self), concatMap(writeChunk), mergeMap(out => toChannel(f(out)), {
|
|
2557
|
-
concurrency: n,
|
|
2558
|
-
mergeStrategy: BufferSliding(),
|
|
2559
|
-
bufferSize
|
|
2560
|
-
}))));
|
|
2561
|
-
/** @internal */
|
|
2562
|
-
const flatten = /*#__PURE__*/Effect.dual(args => isStream(args[0]), (self, options) => flatMap(self, Effect.identity, options));
|
|
2563
|
-
/** @internal */
|
|
2564
|
-
const flattenChunks = self => {
|
|
2565
|
-
const flatten = readWithCause({
|
|
2566
|
-
onInput: chunks => flatMap$1(writeChunk(chunks), () => flatten),
|
|
2567
|
-
onFailure: failCause$2,
|
|
2568
|
-
onDone: () => void_
|
|
2569
|
-
});
|
|
2570
|
-
return new StreamImpl(Effect.pipe(toChannel(self), pipeTo(flatten)));
|
|
2571
|
-
};
|
|
2572
|
-
/** @internal */
|
|
2573
|
-
const flattenExitOption = self => {
|
|
2574
|
-
const processChunk = (chunk, cont) => {
|
|
2575
|
-
const [toEmit, rest] = Effect.pipe(chunk, Effect.splitWhere(exit => !MutableQueue.isSuccess(exit)));
|
|
2576
|
-
const next = Effect.pipe(Effect.head(rest), Effect.match({
|
|
2577
|
-
onNone: () => cont,
|
|
2578
|
-
onSome: MutableQueue.match({
|
|
2579
|
-
onFailure: cause => Effect.match(flipCauseOption(cause), {
|
|
2580
|
-
onNone: () => void_,
|
|
2581
|
-
onSome: failCause$2
|
|
2582
|
-
}),
|
|
2583
|
-
onSuccess: () => void_
|
|
2584
|
-
})
|
|
2585
|
-
}));
|
|
2586
|
-
return Effect.pipe(write(Effect.pipe(toEmit, Effect.filterMap(exit => MutableQueue.isSuccess(exit) ? Effect.some(exit.value) : Effect.none()))), flatMap$1(() => next));
|
|
2587
|
-
};
|
|
2588
|
-
const process = readWithCause({
|
|
2589
|
-
onInput: chunk => processChunk(chunk, process),
|
|
2590
|
-
onFailure: cause => failCause$2(cause),
|
|
2591
|
-
onDone: () => void_
|
|
2592
|
-
});
|
|
2593
|
-
return new StreamImpl(Effect.pipe(toChannel(self), pipeTo(process)));
|
|
2594
|
-
};
|
|
2595
|
-
/** @internal */
|
|
2596
|
-
const flattenTake = self => flattenChunks(flattenExitOption(Effect.pipe(self, map(take => take.exit))));
|
|
2597
|
-
/** @internal */
|
|
2598
|
-
const toChannel = stream => {
|
|
2599
|
-
if ("channel" in stream) {
|
|
2600
|
-
return stream.channel;
|
|
2601
|
-
} else if (Effect.isEffect(stream)) {
|
|
2602
|
-
return toChannel(fromEffect(stream));
|
|
2603
|
-
} else {
|
|
2604
|
-
throw new TypeError(`Expected a Stream.`);
|
|
2605
|
-
}
|
|
2606
|
-
};
|
|
2607
|
-
/** @internal */
|
|
2608
|
-
const fromEffect = effect => Effect.pipe(effect, Effect.mapError(Effect.some), fromEffectOption);
|
|
2609
|
-
/** @internal */
|
|
2610
|
-
const fromEffectOption = effect => new StreamImpl(unwrap(Effect.match$2(effect, {
|
|
2611
|
-
onFailure: Effect.match({
|
|
2612
|
-
onNone: () => void_,
|
|
2613
|
-
onSome: fail
|
|
2614
|
-
}),
|
|
2615
|
-
onSuccess: a => write(Effect.of(a))
|
|
2616
|
-
})));
|
|
2617
|
-
/** @internal */
|
|
2618
|
-
const fromQueue$1 = (queue, options) => Effect.pipe(takeBetween(queue, 1, options?.maxChunkSize ?? DefaultChunkSize), Effect.catchAllCause(cause => Effect.pipe(isShutdown(queue), Effect.flatMap$1(isShutdown => isShutdown && isInterrupted(cause) ? end() : failCause(cause)))), repeatEffectChunkOption, options?.shutdown ? ensuring(shutdown(queue)) : Effect.identity);
|
|
2619
|
-
/** @internal */
|
|
2620
|
-
const map = /*#__PURE__*/Effect.dual(2, (self, f) => new StreamImpl(Effect.pipe(toChannel(self), mapOut(Effect.map$3(f)))));
|
|
2621
|
-
/** @internal */
|
|
2622
|
-
const mapEffectSequential = /*#__PURE__*/Effect.dual(2, (self, f) => {
|
|
2623
|
-
const loop = iterator => {
|
|
2624
|
-
const next = iterator.next();
|
|
2625
|
-
if (next.done) {
|
|
2626
|
-
return readWithCause({
|
|
2627
|
-
onInput: elem => loop(elem[Symbol.iterator]()),
|
|
2628
|
-
onFailure: failCause$2,
|
|
2629
|
-
onDone: succeed
|
|
2630
|
-
});
|
|
2631
|
-
} else {
|
|
2632
|
-
const value = next.value;
|
|
2633
|
-
return unwrap(Effect.map$2(f(value), a2 => flatMap$1(write(Effect.of(a2)), () => loop(iterator))));
|
|
2634
|
-
}
|
|
2635
|
-
};
|
|
2636
|
-
return new StreamImpl(Effect.pipe(toChannel(self), pipeTo(suspend$1(() => loop(Effect.empty$2()[Symbol.iterator]())))));
|
|
2637
|
-
});
|
|
2638
|
-
/** @internal */
|
|
2639
|
-
const mapEffectPar = /*#__PURE__*/Effect.dual(3, (self, n, f) => new StreamImpl(Effect.pipe(toChannel(self), concatMap(writeChunk), mapOutEffectPar(f, n), mapOut(Effect.of))));
|
|
2640
|
-
/** @internal */
|
|
2641
|
-
const repeatEffectChunkOption = effect => unfoldChunkEffect(effect, effect => Effect.pipe(Effect.map$2(effect, chunk => Effect.some([chunk, effect])), Effect.catchAll(Effect.match({
|
|
2642
|
-
onNone: () => Effect.succeed(Effect.none()),
|
|
2643
|
-
onSome: Effect.fail$1
|
|
2644
|
-
}))));
|
|
2645
|
-
/** @internal */
|
|
2646
|
-
const run = /*#__PURE__*/Effect.dual(2, (self, sink) => toChannel(self).pipe(pipeToOrFail(toChannel$1(sink)), runDrain$2));
|
|
2647
|
-
/** @internal */
|
|
2648
|
-
const runDrain$1 = self => run(self, drain);
|
|
2649
|
-
/** @internal */
|
|
2650
|
-
const scopedWith = f => new StreamImpl(scopedWith$1(scope => f(scope).pipe(Effect.map$2(Effect.of))));
|
|
2651
|
-
/** @internal */
|
|
2652
|
-
const suspend = stream => new StreamImpl(suspend$1(() => toChannel(stream())));
|
|
2653
|
-
/** @internal */
|
|
2654
|
-
const unfoldChunkEffect = (s, f) => suspend(() => {
|
|
2655
|
-
const loop = s => unwrap(Effect.map$2(f(s), Effect.match({
|
|
2656
|
-
onNone: () => void_,
|
|
2657
|
-
onSome: ([chunk, s]) => flatMap$1(write(chunk), () => loop(s))
|
|
2658
|
-
})));
|
|
2659
|
-
return new StreamImpl(loop(s));
|
|
2660
|
-
});
|
|
2661
|
-
/** @internal */
|
|
2662
|
-
const unwrapScopedWith = f => flatten(scopedWith(scope => f(scope)));
|
|
2663
|
-
|
|
2664
|
-
/** @internal */
|
|
2665
|
-
const GroupBySymbolKey = "effect/GroupBy";
|
|
2666
|
-
/** @internal */
|
|
2667
|
-
const GroupByTypeId = /*#__PURE__*/Symbol.for(GroupBySymbolKey);
|
|
2668
|
-
const groupByVariance = {
|
|
2669
|
-
/* c8 ignore next */
|
|
2670
|
-
_R: _ => _,
|
|
2671
|
-
/* c8 ignore next */
|
|
2672
|
-
_E: _ => _,
|
|
2673
|
-
/* c8 ignore next */
|
|
2674
|
-
_K: _ => _,
|
|
2675
|
-
/* c8 ignore next */
|
|
2676
|
-
_V: _ => _
|
|
2677
|
-
};
|
|
2678
|
-
/** @internal */
|
|
2679
|
-
const isGroupBy = u => Effect.hasProperty(u, GroupByTypeId);
|
|
2680
|
-
/** @internal */
|
|
2681
|
-
const evaluate = /*#__PURE__*/Effect.dual(args => isGroupBy(args[0]), (self, f, options) => flatMap(self.grouped, ([key, queue]) => f(key, flattenTake(fromQueue$1(queue, {
|
|
2682
|
-
shutdown: true
|
|
2683
|
-
}))), {
|
|
2684
|
-
concurrency: "unbounded",
|
|
2685
|
-
bufferSize: options?.bufferSize ?? 16
|
|
2686
|
-
}));
|
|
2687
|
-
/** @internal */
|
|
2688
|
-
const make = grouped => ({
|
|
2689
|
-
[GroupByTypeId]: groupByVariance,
|
|
2690
|
-
pipe() {
|
|
2691
|
-
return Effect.pipeArguments(this, arguments);
|
|
2692
|
-
},
|
|
2693
|
-
grouped
|
|
2694
|
-
});
|
|
2695
|
-
/** @internal */
|
|
2696
|
-
const mapEffectOptions = /*#__PURE__*/Effect.dual(args => typeof args[0] !== "function", (self, f, options) => {
|
|
2697
|
-
if (options?.key) {
|
|
2698
|
-
return evaluate(groupByKey(self, options.key, {
|
|
2699
|
-
bufferSize: options.bufferSize
|
|
2700
|
-
}), (_, s) => mapEffectSequential(s, f));
|
|
2701
|
-
}
|
|
2702
|
-
return matchConcurrency(options?.concurrency, () => mapEffectSequential(self, f), n => options?.unordered ? flatMap(self, a => fromEffect(f(a)), {
|
|
2703
|
-
concurrency: n
|
|
2704
|
-
}) : mapEffectPar(self, n, f));
|
|
2705
|
-
});
|
|
2706
|
-
/** @internal */
|
|
2707
|
-
const groupByKey = /*#__PURE__*/Effect.dual(args => typeof args[0] !== "function", (self, f, options) => {
|
|
2708
|
-
const loop = (map, outerQueue) => readWithCause({
|
|
2709
|
-
onInput: input => flatMap$1(fromEffect$3(Effect.forEach(groupByIterable(input, f), ([key, values]) => {
|
|
2710
|
-
const innerQueue = map.get(key);
|
|
2711
|
-
if (innerQueue === undefined) {
|
|
2712
|
-
return Effect.pipe(bounded(options?.bufferSize ?? 16), Effect.flatMap$1(innerQueue => Effect.pipe(Effect.sync$1(() => {
|
|
2713
|
-
map.set(key, innerQueue);
|
|
2714
|
-
}), Effect.zipRight$1(offer(outerQueue, of([key, innerQueue]))), Effect.zipRight$1(Effect.pipe(offer(innerQueue, chunk(values)), Effect.catchSomeCause(cause => isInterruptedOnly(cause) ? Effect.some(Effect._void) : Effect.none()))))));
|
|
2715
|
-
}
|
|
2716
|
-
return Effect.catchSomeCause(offer(innerQueue, chunk(values)), cause => isInterruptedOnly(cause) ? Effect.some(Effect._void) : Effect.none());
|
|
2717
|
-
}, {
|
|
2718
|
-
discard: true
|
|
2719
|
-
})), () => loop(map, outerQueue)),
|
|
2720
|
-
onFailure: cause => fromEffect$3(offer(outerQueue, failCause$1(cause))),
|
|
2721
|
-
onDone: () => fromEffect$3(Effect.pipe(Effect.forEach(map.entries(), ([_, innerQueue]) => Effect.pipe(offer(innerQueue, end$1), Effect.catchSomeCause(cause => isInterruptedOnly(cause) ? Effect.some(Effect._void) : Effect.none())), {
|
|
2722
|
-
discard: true
|
|
2723
|
-
}), Effect.zipRight$1(offer(outerQueue, end$1))))
|
|
2724
|
-
});
|
|
2725
|
-
return make(unwrapScopedWith(scope => Effect.gen(function* () {
|
|
2726
|
-
const map = new Map();
|
|
2727
|
-
const queue = yield* unbounded();
|
|
2728
|
-
yield* Effect.addFinalizer(scope, shutdown(queue));
|
|
2729
|
-
return yield* toChannel(self).pipe(pipeTo(loop(map, queue)), drain$1, runIn(scope), Effect.forkIn(scope), Effect.as(flattenTake(fromQueue$1(queue, {
|
|
2730
|
-
shutdown: true
|
|
2731
|
-
}))));
|
|
2732
|
-
})));
|
|
2733
|
-
});
|
|
2734
|
-
/**
|
|
2735
|
-
* A variant of `groupBy` that retains the insertion order of keys.
|
|
2736
|
-
*
|
|
2737
|
-
* @internal
|
|
2738
|
-
*/
|
|
2739
|
-
const groupByIterable = /*#__PURE__*/Effect.dual(2, (iterable, f) => {
|
|
2740
|
-
const builder = [];
|
|
2741
|
-
const iterator = iterable[Symbol.iterator]();
|
|
2742
|
-
const map = new Map();
|
|
2743
|
-
let next;
|
|
2744
|
-
while ((next = iterator.next()) && !next.done) {
|
|
2745
|
-
const value = next.value;
|
|
2746
|
-
const key = f(value);
|
|
2747
|
-
if (map.has(key)) {
|
|
2748
|
-
const innerBuilder = map.get(key);
|
|
2749
|
-
innerBuilder.push(value);
|
|
2750
|
-
} else {
|
|
2751
|
-
const innerBuilder = [value];
|
|
2752
|
-
builder.push([key, innerBuilder]);
|
|
2753
|
-
map.set(key, innerBuilder);
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
return Effect.unsafeFromArray(builder.map(tuple => [tuple[0], Effect.unsafeFromArray(tuple[1])]));
|
|
2757
|
-
});
|
|
2758
|
-
|
|
2759
|
-
/**
|
|
2760
|
-
* Creates a stream from a queue of values
|
|
2761
|
-
*
|
|
2762
|
-
* **Options**
|
|
2763
|
-
*
|
|
2764
|
-
* - `maxChunkSize`: The maximum number of queued elements to put in one chunk in the stream
|
|
2765
|
-
* - `shutdown`: If `true`, the queue will be shutdown after the stream is evaluated (defaults to `false`)
|
|
2766
|
-
*
|
|
2767
|
-
* @since 2.0.0
|
|
2768
|
-
* @category constructors
|
|
2769
|
-
*/
|
|
2770
|
-
const fromQueue = fromQueue$1;
|
|
2771
|
-
/**
|
|
2772
|
-
* Maps over elements of the stream with the specified effectful function.
|
|
2773
|
-
*
|
|
2774
|
-
* @example
|
|
2775
|
-
* ```ts
|
|
2776
|
-
* import { Effect, Random, Stream } from "effect"
|
|
2777
|
-
*
|
|
2778
|
-
* const stream = Stream.make(10, 20, 30).pipe(
|
|
2779
|
-
* Stream.mapEffect((n) => Random.nextIntBetween(0, n))
|
|
2780
|
-
* )
|
|
2781
|
-
*
|
|
2782
|
-
* Effect.runPromise(Stream.runCollect(stream)).then(console.log)
|
|
2783
|
-
* // Example Output: { _id: 'Chunk', values: [ 7, 19, 8 ] }
|
|
2784
|
-
* ```
|
|
2785
|
-
*
|
|
2786
|
-
* @since 2.0.0
|
|
2787
|
-
* @category mapping
|
|
2788
|
-
*/
|
|
2789
|
-
const mapEffect = mapEffectOptions;
|
|
2790
|
-
/**
|
|
2791
|
-
* Runs the stream only for its effects. The emitted elements are discarded.
|
|
2792
|
-
*
|
|
2793
|
-
* @since 2.0.0
|
|
2794
|
-
* @category destructors
|
|
2795
|
-
*/
|
|
2796
|
-
const runDrain = runDrain$1;
|
|
2797
|
-
|
|
2798
|
-
class ReactiveControllerHost {
|
|
2799
|
-
controllers = new Set();
|
|
2800
|
-
addController(controller) {
|
|
2801
|
-
this.controllers.add(controller);
|
|
2802
|
-
}
|
|
2803
|
-
removeController(controller) {
|
|
2804
|
-
this.controllers.delete(controller);
|
|
2805
|
-
}
|
|
2806
|
-
get activeControllers() {
|
|
2807
|
-
return Array.from(this.controllers).filter(controller => !controller.disabled);
|
|
2808
|
-
}
|
|
2809
|
-
connectedCallback() {
|
|
2810
|
-
if (!this.controllers.size) {
|
|
2811
|
-
console.warn('ReactiveControllerHost connected with no controllers registered.', this);
|
|
2812
|
-
}
|
|
2813
|
-
this.activeControllers.forEach(controller => controller.hostConnected?.());
|
|
2814
|
-
}
|
|
2815
|
-
disconnectedCallback() {
|
|
2816
|
-
this.activeControllers.forEach(controller => controller.hostDisconnected?.());
|
|
2817
|
-
}
|
|
2818
|
-
componentWillLoad() {
|
|
2819
|
-
this.activeControllers.forEach(controller => controller.hostWillLoad?.());
|
|
2820
|
-
}
|
|
2821
|
-
componentDidLoad() {
|
|
2822
|
-
this.activeControllers.forEach(controller => controller.hostDidLoad?.());
|
|
2823
|
-
}
|
|
2824
|
-
componentWillRender() {
|
|
2825
|
-
this.activeControllers.forEach(controller => controller.hostWillRender?.());
|
|
2826
|
-
}
|
|
2827
|
-
componentDidRender() {
|
|
2828
|
-
this.activeControllers.forEach(controller => controller.hostDidRender?.());
|
|
2829
|
-
}
|
|
2830
|
-
componentWillUpdate() {
|
|
2831
|
-
this.activeControllers.forEach(controller => controller.hostWillUpdate?.());
|
|
2832
|
-
}
|
|
2833
|
-
componentDidUpdate() {
|
|
2834
|
-
this.activeControllers.forEach(controller => controller.hostDidUpdate?.());
|
|
2835
|
-
}
|
|
2836
|
-
}
|
|
2837
|
-
|
|
2838
|
-
class AriaValidationController {
|
|
2839
|
-
host;
|
|
2840
|
-
config;
|
|
2841
|
-
static get globalValidationEnabled() {
|
|
2842
|
-
return index.Build.isDev;
|
|
2843
|
-
}
|
|
2844
|
-
static axe = this.globalValidationEnabled ? Promise.resolve().then(function () { return require('./axe-BNqwbBGU.js'); }).then(function (n) { return n.axe; }) : null;
|
|
2845
|
-
static axeQueue = null;
|
|
2846
|
-
static axeStreamFiber = null;
|
|
2847
|
-
visibilityObserver;
|
|
2848
|
-
elementQueued = false;
|
|
2849
|
-
elementValidated = false;
|
|
2850
|
-
knownValidationErrors = [];
|
|
2851
|
-
get disabled() {
|
|
2852
|
-
return true;
|
|
2853
|
-
}
|
|
2854
|
-
constructor(host, config) {
|
|
2855
|
-
this.host = host;
|
|
2856
|
-
this.config = config;
|
|
2857
|
-
AriaValidationController.initializeAxeStream();
|
|
2858
|
-
}
|
|
2859
|
-
static initializeAxeStream() {
|
|
2860
|
-
if (!this.globalValidationEnabled)
|
|
2861
|
-
return;
|
|
2862
|
-
if (this.axeStreamFiber)
|
|
2863
|
-
return;
|
|
2864
|
-
const program = Effect.gen(function* () {
|
|
2865
|
-
const queue = (AriaValidationController.axeQueue = yield* bounded(100));
|
|
2866
|
-
const axeLib = yield* Effect.promise(() => AriaValidationController.axe);
|
|
2867
|
-
if (!axeLib) {
|
|
2868
|
-
console.error('Axe library not available, ARIA validation will not run.');
|
|
2869
|
-
return;
|
|
2870
|
-
}
|
|
2871
|
-
const stream = fromQueue(queue).pipe(mapEffect(({ context, onComplete }) => Effect.async(resume => {
|
|
2872
|
-
axeLib.run(context, {}, (error, results) => {
|
|
2873
|
-
onComplete(error, results);
|
|
2874
|
-
resume(Effect._void);
|
|
2875
|
-
});
|
|
2876
|
-
})));
|
|
2877
|
-
yield* runDrain(stream);
|
|
2878
|
-
});
|
|
2879
|
-
this.axeStreamFiber = Effect.runFork(program);
|
|
2880
|
-
}
|
|
2881
|
-
hostDidLoad() {
|
|
2882
|
-
if (this.elementQueued || this.elementValidated)
|
|
2883
|
-
return;
|
|
2884
|
-
if (!this.host.el.checkVisibility()) {
|
|
2885
|
-
this.observeVisibilityOnce();
|
|
2886
|
-
return;
|
|
2887
|
-
}
|
|
2888
|
-
this.enqueueValidation();
|
|
2889
|
-
}
|
|
2890
|
-
hostDidUpdate() {
|
|
2891
|
-
this.checkLazyValidation();
|
|
2892
|
-
}
|
|
2893
|
-
hostDisconnected() {
|
|
2894
|
-
this.discardVisibilityObserver();
|
|
2895
|
-
}
|
|
2896
|
-
observeVisibilityOnce() {
|
|
2897
|
-
this.visibilityObserver = new IntersectionObserver(entries => {
|
|
2898
|
-
for (const entry of entries) {
|
|
2899
|
-
if (entry.target !== this.host.el)
|
|
2900
|
-
continue;
|
|
2901
|
-
if (!entry.isIntersecting)
|
|
2902
|
-
continue;
|
|
2903
|
-
this.checkLazyValidation();
|
|
2904
|
-
this.discardVisibilityObserver();
|
|
2905
|
-
}
|
|
2906
|
-
}, {
|
|
2907
|
-
root: this.host.el.parentElement,
|
|
2908
|
-
rootMargin: '0px',
|
|
2909
|
-
threshold: 0.01,
|
|
2910
|
-
});
|
|
2911
|
-
this.visibilityObserver.observe(this.host.el);
|
|
2912
|
-
}
|
|
2913
|
-
checkLazyValidation() {
|
|
2914
|
-
if (!this.config?.reValidateOnPropChanges && (this.elementQueued || this.elementValidated))
|
|
2915
|
-
return;
|
|
2916
|
-
this.enqueueValidation();
|
|
2917
|
-
}
|
|
2918
|
-
enqueueValidation() {
|
|
2919
|
-
return;
|
|
2920
|
-
}
|
|
2921
|
-
discardVisibilityObserver() {
|
|
2922
|
-
if (!this.visibilityObserver)
|
|
2923
|
-
return;
|
|
2924
|
-
this.visibilityObserver.disconnect();
|
|
2925
|
-
this.visibilityObserver = undefined;
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
exports.AriaValidationController = AriaValidationController;
|
|
2930
|
-
exports.ReactiveControllerHost = ReactiveControllerHost;
|