@typed/fx 1.27.4 → 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/cjs/AsyncData.js +1 -1
  2. package/dist/cjs/AsyncData.js.map +1 -1
  3. package/dist/cjs/Emitter.js +3 -3
  4. package/dist/cjs/Emitter.js.map +1 -1
  5. package/dist/cjs/Form.js +15 -15
  6. package/dist/cjs/Form.js.map +1 -1
  7. package/dist/cjs/FormEntry.js +3 -3
  8. package/dist/cjs/FormEntry.js.map +1 -1
  9. package/dist/cjs/Fx.js +11 -9
  10. package/dist/cjs/Fx.js.map +1 -1
  11. package/dist/cjs/Idle.js +8 -8
  12. package/dist/cjs/Idle.js.map +1 -1
  13. package/dist/cjs/Match.js +17 -17
  14. package/dist/cjs/Match.js.map +1 -1
  15. package/dist/cjs/Pull.js +3 -3
  16. package/dist/cjs/Pull.js.map +1 -1
  17. package/dist/cjs/Push.js +1 -1
  18. package/dist/cjs/Push.js.map +1 -1
  19. package/dist/cjs/RefArray.js +2 -2
  20. package/dist/cjs/RefArray.js.map +1 -1
  21. package/dist/cjs/RefChunk.js +1 -1
  22. package/dist/cjs/RefChunk.js.map +1 -1
  23. package/dist/cjs/RefHashMap.js +1 -1
  24. package/dist/cjs/RefHashMap.js.map +1 -1
  25. package/dist/cjs/RefHashSet.js +1 -1
  26. package/dist/cjs/RefHashSet.js.map +1 -1
  27. package/dist/cjs/RefSubject.js +150 -75
  28. package/dist/cjs/RefSubject.js.map +1 -1
  29. package/dist/cjs/Sink.js +14 -14
  30. package/dist/cjs/Sink.js.map +1 -1
  31. package/dist/cjs/Stream.js +1 -1
  32. package/dist/cjs/Stream.js.map +1 -1
  33. package/dist/cjs/Subject.js +9 -11
  34. package/dist/cjs/Subject.js.map +1 -1
  35. package/dist/cjs/Typeclass.js +1 -1
  36. package/dist/cjs/Typeclass.js.map +1 -1
  37. package/dist/cjs/Versioned.js +4 -4
  38. package/dist/cjs/Versioned.js.map +1 -1
  39. package/dist/cjs/index.js +1 -1
  40. package/dist/cjs/index.js.map +1 -1
  41. package/dist/cjs/internal/DeferredRef.js +14 -11
  42. package/dist/cjs/internal/DeferredRef.js.map +1 -1
  43. package/dist/cjs/internal/core.js +71 -42
  44. package/dist/cjs/internal/core.js.map +1 -1
  45. package/dist/cjs/internal/diff.js +1 -1
  46. package/dist/cjs/internal/diff.js.map +1 -1
  47. package/dist/cjs/internal/effect-loop-operator.js +1 -1
  48. package/dist/cjs/internal/effect-loop-operator.js.map +1 -1
  49. package/dist/cjs/internal/effect-operator.js +3 -3
  50. package/dist/cjs/internal/effect-operator.js.map +1 -1
  51. package/dist/cjs/internal/effect-producer.js +3 -3
  52. package/dist/cjs/internal/effect-producer.js.map +1 -1
  53. package/dist/cjs/internal/helpers.js +63 -42
  54. package/dist/cjs/internal/helpers.js.map +1 -1
  55. package/dist/cjs/internal/keyed.js +34 -26
  56. package/dist/cjs/internal/keyed.js.map +1 -1
  57. package/dist/cjs/internal/loop-operator.js +1 -1
  58. package/dist/cjs/internal/loop-operator.js.map +1 -1
  59. package/dist/cjs/internal/operator.js +1 -1
  60. package/dist/cjs/internal/operator.js.map +1 -1
  61. package/dist/cjs/internal/protos.js +1 -1
  62. package/dist/cjs/internal/protos.js.map +1 -1
  63. package/dist/cjs/internal/provide.js +1 -1
  64. package/dist/cjs/internal/provide.js.map +1 -1
  65. package/dist/cjs/internal/share.js +8 -13
  66. package/dist/cjs/internal/share.js.map +1 -1
  67. package/dist/cjs/internal/sync-operator.js +4 -4
  68. package/dist/cjs/internal/sync-operator.js.map +1 -1
  69. package/dist/cjs/internal/sync-producer.js +27 -23
  70. package/dist/cjs/internal/sync-producer.js.map +1 -1
  71. package/dist/cjs/internal/withKey.js +7 -7
  72. package/dist/cjs/internal/withKey.js.map +1 -1
  73. package/dist/dts/AsyncData.d.ts +2 -2
  74. package/dist/dts/AsyncData.d.ts.map +1 -1
  75. package/dist/dts/Emitter.d.ts +1 -1
  76. package/dist/dts/Emitter.d.ts.map +1 -1
  77. package/dist/dts/Fx.d.ts +39 -13
  78. package/dist/dts/Fx.d.ts.map +1 -1
  79. package/dist/dts/Idle.d.ts.map +1 -1
  80. package/dist/dts/Match.d.ts +1 -1
  81. package/dist/dts/Match.d.ts.map +1 -1
  82. package/dist/dts/Push.d.ts +4 -1
  83. package/dist/dts/Push.d.ts.map +1 -1
  84. package/dist/dts/RefArray.d.ts +1 -2
  85. package/dist/dts/RefArray.d.ts.map +1 -1
  86. package/dist/dts/RefChunk.d.ts.map +1 -1
  87. package/dist/dts/RefHashMap.d.ts +1 -1
  88. package/dist/dts/RefHashMap.d.ts.map +1 -1
  89. package/dist/dts/RefHashSet.d.ts.map +1 -1
  90. package/dist/dts/RefSubject.d.ts +64 -3
  91. package/dist/dts/RefSubject.d.ts.map +1 -1
  92. package/dist/dts/Sink.d.ts +2 -1
  93. package/dist/dts/Sink.d.ts.map +1 -1
  94. package/dist/dts/Subject.d.ts +2 -1
  95. package/dist/dts/Subject.d.ts.map +1 -1
  96. package/dist/dts/Versioned.d.ts +3 -1
  97. package/dist/dts/Versioned.d.ts.map +1 -1
  98. package/dist/dts/internal/DeferredRef.d.ts +6 -4
  99. package/dist/dts/internal/DeferredRef.d.ts.map +1 -1
  100. package/dist/dts/internal/core.d.ts +25 -12
  101. package/dist/dts/internal/core.d.ts.map +1 -1
  102. package/dist/dts/internal/diff.d.ts +1 -1
  103. package/dist/dts/internal/diff.d.ts.map +1 -1
  104. package/dist/dts/internal/effect-operator.d.ts.map +1 -1
  105. package/dist/dts/internal/helpers.d.ts +8 -6
  106. package/dist/dts/internal/helpers.d.ts.map +1 -1
  107. package/dist/dts/internal/keyed.d.ts +2 -2
  108. package/dist/dts/internal/keyed.d.ts.map +1 -1
  109. package/dist/dts/internal/loop-operator.d.ts +1 -1
  110. package/dist/dts/internal/loop-operator.d.ts.map +1 -1
  111. package/dist/dts/internal/protos.d.ts +1 -1
  112. package/dist/dts/internal/protos.d.ts.map +1 -1
  113. package/dist/dts/internal/provide.d.ts.map +1 -1
  114. package/dist/dts/internal/share.d.ts +1 -1
  115. package/dist/dts/internal/share.d.ts.map +1 -1
  116. package/dist/dts/internal/strategies.d.ts.map +1 -1
  117. package/dist/dts/internal/sync-operator.d.ts.map +1 -1
  118. package/dist/dts/internal/sync-producer.d.ts +4 -4
  119. package/dist/dts/internal/sync-producer.d.ts.map +1 -1
  120. package/dist/esm/Emitter.js +1 -1
  121. package/dist/esm/Emitter.js.map +1 -1
  122. package/dist/esm/Form.js +14 -14
  123. package/dist/esm/Form.js.map +1 -1
  124. package/dist/esm/FormEntry.js +2 -2
  125. package/dist/esm/FormEntry.js.map +1 -1
  126. package/dist/esm/Fx.js +16 -5
  127. package/dist/esm/Fx.js.map +1 -1
  128. package/dist/esm/Idle.js +7 -7
  129. package/dist/esm/Idle.js.map +1 -1
  130. package/dist/esm/Match.js +17 -17
  131. package/dist/esm/Match.js.map +1 -1
  132. package/dist/esm/Pull.js +2 -2
  133. package/dist/esm/Push.js.map +1 -1
  134. package/dist/esm/RefArray.js +1 -1
  135. package/dist/esm/RefArray.js.map +1 -1
  136. package/dist/esm/RefHashMap.js.map +1 -1
  137. package/dist/esm/RefSubject.js +140 -59
  138. package/dist/esm/RefSubject.js.map +1 -1
  139. package/dist/esm/Sink.js +13 -13
  140. package/dist/esm/Sink.js.map +1 -1
  141. package/dist/esm/Subject.js +8 -10
  142. package/dist/esm/Subject.js.map +1 -1
  143. package/dist/esm/Versioned.js +1 -1
  144. package/dist/esm/Versioned.js.map +1 -1
  145. package/dist/esm/internal/DeferredRef.js +13 -10
  146. package/dist/esm/internal/DeferredRef.js.map +1 -1
  147. package/dist/esm/internal/core.js +70 -37
  148. package/dist/esm/internal/core.js.map +1 -1
  149. package/dist/esm/internal/diff.js.map +1 -1
  150. package/dist/esm/internal/effect-operator.js +2 -2
  151. package/dist/esm/internal/effect-producer.js +1 -1
  152. package/dist/esm/internal/helpers.js +62 -39
  153. package/dist/esm/internal/helpers.js.map +1 -1
  154. package/dist/esm/internal/keyed.js +26 -17
  155. package/dist/esm/internal/keyed.js.map +1 -1
  156. package/dist/esm/internal/share.js +7 -12
  157. package/dist/esm/internal/share.js.map +1 -1
  158. package/dist/esm/internal/sync-operator.js +3 -3
  159. package/dist/esm/internal/sync-operator.js.map +1 -1
  160. package/dist/esm/internal/sync-producer.js +7 -5
  161. package/dist/esm/internal/sync-producer.js.map +1 -1
  162. package/dist/esm/internal/withKey.js +6 -6
  163. package/dist/esm/internal/withKey.js.map +1 -1
  164. package/package.json +8 -7
  165. package/src/Emitter.ts +2 -1
  166. package/src/Form.ts +22 -30
  167. package/src/FormEntry.ts +2 -2
  168. package/src/Fx.ts +54 -36
  169. package/src/Idle.ts +7 -7
  170. package/src/Match.ts +24 -26
  171. package/src/Pull.ts +2 -2
  172. package/src/Push.ts +4 -1
  173. package/src/RefArray.ts +1 -1
  174. package/src/RefHashMap.ts +1 -1
  175. package/src/RefSubject.ts +262 -98
  176. package/src/Sink.ts +15 -14
  177. package/src/Subject.ts +19 -14
  178. package/src/Versioned.ts +4 -2
  179. package/src/internal/DeferredRef.ts +21 -11
  180. package/src/internal/core.ts +92 -61
  181. package/src/internal/diff.ts +1 -1
  182. package/src/internal/effect-operator.ts +2 -2
  183. package/src/internal/effect-producer.ts +3 -3
  184. package/src/internal/helpers.ts +89 -42
  185. package/src/internal/keyed.ts +47 -42
  186. package/src/internal/loop-operator.ts +1 -1
  187. package/src/internal/protos.ts +1 -1
  188. package/src/internal/share.ts +11 -26
  189. package/src/internal/sync-operator.ts +3 -3
  190. package/src/internal/sync-producer.ts +7 -5
  191. package/src/internal/withKey.ts +6 -6
@@ -221,7 +221,7 @@ export function compileCauseEffectOperatorSink<R>(
221
221
  op.f(a),
222
222
  Sink.make(
223
223
  (cause2) => sink.onFailure(Cause.sequential(a, cause2)),
224
- (b) => b ? sink.onFailure(a) : Effect.unit
224
+ (b) => b ? sink.onFailure(a) : Effect.void
225
225
  )
226
226
  ),
227
227
  sink.onSuccess
@@ -234,7 +234,7 @@ export function compileCauseEffectOperatorSink<R>(
234
234
  Sink.make(
235
235
  (cause2) => sink.onFailure(Cause.sequential(a, cause2)),
236
236
  Option.match({
237
- onNone: () => Effect.unit,
237
+ onNone: () => Effect.void,
238
238
  onSome: sink.onFailure
239
239
  })
240
240
  )
@@ -1,4 +1,4 @@
1
- import type { Cause } from "effect"
1
+ import type * as Cause from "effect/Cause"
2
2
  import * as Effect from "effect/Effect"
3
3
  import * as Schedule from "effect/Schedule"
4
4
  import type * as Sink from "../Sink.js"
@@ -94,7 +94,7 @@ export function runEffect<A, E, R, B, E2, R2>(
94
94
  Effect.asyncEffect((resume) => {
95
95
  const onFailure = (cause: Cause.Cause<E | E2>) => Effect.succeed(resume(Effect.failCause(cause)))
96
96
 
97
- return Effect.asUnit(Effect.matchCauseEffect(
97
+ return Effect.asVoid(Effect.matchCauseEffect(
98
98
  Effect.scheduleFrom(
99
99
  producer.input,
100
100
  i,
@@ -103,7 +103,7 @@ export function runEffect<A, E, R, B, E2, R2>(
103
103
  (a) => Effect.catchAllCause(f(a), onFailure)
104
104
  )
105
105
  ),
106
- { onFailure, onSuccess: () => Effect.succeed(resume(Effect.unit)) }
106
+ { onFailure, onSuccess: () => Effect.succeed(resume(Effect.void)) }
107
107
  ))
108
108
  })
109
109
  )
@@ -1,65 +1,112 @@
1
1
  import { getOption } from "@typed/context"
2
- import { Equivalence, Unify } from "effect"
3
- import type { Duration, Exit } from "effect"
4
2
  import * as Cause from "effect/Cause"
3
+ import * as Deferred from "effect/Deferred"
4
+ import type * as Duration from "effect/Duration"
5
5
  import * as Effect from "effect/Effect"
6
6
  import * as Effectable from "effect/Effectable"
7
7
  import * as Equal from "effect/Equal"
8
+ import * as Equivalence from "effect/Equivalence"
8
9
  import * as ExecutionStrategy from "effect/ExecutionStrategy"
10
+ import * as Exit from "effect/Exit"
9
11
  import * as Fiber from "effect/Fiber"
12
+ import type * as FiberId from "effect/FiberId"
10
13
  import * as FiberSet from "effect/FiberSet"
11
14
  import * as Option from "effect/Option"
12
15
  import * as Ref from "effect/Ref"
13
16
  import * as Scope from "effect/Scope"
14
17
  import * as SynchronizedRef from "effect/SynchronizedRef"
15
18
  import * as TestClock from "effect/TestClock"
19
+ import * as Unify from "effect/Unify"
16
20
  import type { FlattenStrategy, FxFork, ScopedFork } from "../Fx.js"
17
21
  import type * as Sink from "../Sink.js"
18
22
 
19
- export function withBuffers<A, E, R>(size: number, sink: Sink.Sink<A, E, R>) {
20
- const buffers: Array<Array<A>> = Array.from({ length: size }, () => [])
21
- const finished = new Set<number>()
22
- let currentIndex = 0
23
-
24
- const drainBuffer = (index: number): Effect.Effect<void, never, R> => {
25
- const effect = Effect.forEach(buffers[index], sink.onSuccess)
26
- buffers[index] = []
27
-
28
- return Effect.flatMap(effect, () => finished.has(index) ? onEnd(index) : Effect.unit)
29
- }
30
-
31
- const onSuccess = (index: number, value: A) => {
32
- if (index === currentIndex) {
33
- const buffer = buffers[index]
23
+ export function withBuffers<A, E, R>(
24
+ size: number,
25
+ sink: Sink.Sink<A, E, R>,
26
+ id: FiberId.FiberId
27
+ ) {
28
+ const buffers = indexedBuffers(size, sink, id)
29
+ const onSuccess = (index: number, value: A) => buffers.get(index)!.onSuccess(value)
30
+ const onEnd = (index: number) => buffers.get(index)!.onEnd
34
31
 
35
- if (buffer.length === 0) {
36
- return sink.onSuccess(value)
37
- } else {
38
- buffer.push(value)
32
+ return {
33
+ onSuccess: (i: number, a: A) => onSuccess(i, a),
34
+ onEnd: (i: number) => onEnd(i)
35
+ } as const
36
+ }
39
37
 
40
- return drainBuffer(index)
41
- }
42
- } else {
43
- buffers[index].push(value)
38
+ function indexedBuffers<A, E, R>(
39
+ size: number,
40
+ sink: Sink.Sink<A, E, R>,
41
+ id: FiberId.FiberId
42
+ ) {
43
+ const buffers = new Map<number, ReturnType<typeof IndexedBuffer<A, E, R>>>()
44
+
45
+ const last = size - 1
46
+ for (let i = 0; i < size; i++) {
47
+ const deferred = Deferred.unsafeMake<void>(id)
48
+ const state = {
49
+ ready: i === 0,
50
+ deferred
51
+ }
44
52
 
45
- return Effect.unit
53
+ // First should start immediately
54
+ if (i === 0) {
55
+ Deferred.unsafeDone(deferred, Exit.void)
46
56
  }
57
+
58
+ buffers.set(
59
+ i,
60
+ IndexedBuffer(
61
+ state,
62
+ sink,
63
+ i === last ? Effect.void : Effect.suspend(() => {
64
+ const next = buffers.get(i + 1)!
65
+ next.state.ready = true
66
+ return Deferred.done(next.state.deferred, Exit.void)
67
+ })
68
+ )
69
+ )
47
70
  }
48
71
 
49
- const onEnd = (index: number) => {
50
- finished.add(index)
72
+ return buffers
73
+ }
51
74
 
52
- if (index === currentIndex && ++currentIndex < size) {
53
- return drainBuffer(currentIndex)
75
+ function IndexedBuffer<A, E, R>(
76
+ state: {
77
+ ready: boolean
78
+ deferred: Deferred.Deferred<void>
79
+ },
80
+ sink: Sink.Sink<A, E, R>,
81
+ onDone: Effect.Effect<void>
82
+ ) {
83
+ let buffer: Array<A> = []
84
+
85
+ const onSuccess = (value: A) => {
86
+ if (state.ready) {
87
+ if (buffer.length === 0) return sink.onSuccess(value)
88
+ buffer.push(value)
89
+ const effect = Effect.forEach(buffer, sink.onSuccess)
90
+ buffer = []
91
+ return effect
54
92
  } else {
55
- return Effect.unit
93
+ buffer.push(value)
94
+ return Effect.void
56
95
  }
57
96
  }
58
97
 
98
+ const onEnd = Effect.flatMap(Deferred.await(state.deferred), () => {
99
+ if (buffer.length === 0) return onDone
100
+ const effect = Effect.forEach(buffer, sink.onSuccess)
101
+ buffer = []
102
+ return Effect.zipRight(effect, onDone)
103
+ })
104
+
59
105
  return {
106
+ state,
60
107
  onSuccess,
61
108
  onEnd
62
- } as const
109
+ }
63
110
  }
64
111
 
65
112
  export const withScope = <A, E, R>(
@@ -112,7 +159,7 @@ export function withSwitchFork<A, E, R>(
112
159
  return withScopedFork(
113
160
  (fork, scope) =>
114
161
  Effect.flatMap(
115
- SynchronizedRef.make<Fiber.Fiber<unknown>>(Fiber.unit),
162
+ SynchronizedRef.make<Fiber.Fiber<unknown>>(Fiber.void),
116
163
  (ref) => runSwitchFork(ref, fork, scope, f)
117
164
  ),
118
165
  executionStrategy
@@ -164,7 +211,7 @@ export function withExhaustFork<A, E, R>(
164
211
  )
165
212
  )
166
213
  ), scope),
167
- () => Effect.flatMap(Ref.get(ref), (fiber) => fiber ? Fiber.join(fiber) : Effect.unit)
214
+ () => Effect.flatMap(Ref.get(ref), (fiber) => fiber ? Fiber.join(fiber) : Effect.void)
168
215
  )
169
216
  )
170
217
  }, executionStrategy)
@@ -184,7 +231,7 @@ export function withExhaustLatestFork<A, E, R>(
184
231
  const reset = Ref.set(ref, undefined)
185
232
 
186
233
  // Wait for the current fiber to finish
187
- const awaitNext = Effect.flatMap(Ref.get(ref), (fiber) => fiber ? Fiber.join(fiber) : Effect.unit)
234
+ const awaitNext = Effect.flatMap(Ref.get(ref), (fiber) => fiber ? Fiber.join(fiber) : Effect.void)
188
235
 
189
236
  // Run the next value that's be saved for replay if it exists
190
237
 
@@ -192,7 +239,7 @@ export function withExhaustLatestFork<A, E, R>(
192
239
  Ref.get(nextEffect),
193
240
  (next) => {
194
241
  if (Option.isNone(next)) {
195
- return Effect.unit
242
+ return Effect.void
196
243
  }
197
244
 
198
245
  return Effect.all([
@@ -263,7 +310,7 @@ export function withBoundedFork(capacity: number) {
263
310
  )
264
311
  )
265
312
  ), scope),
266
- () => Effect.flatMap(Ref.get(ref), (fibers) => fibers.size > 0 ? Fiber.joinAll(fibers) : Effect.unit)
313
+ () => Effect.flatMap(Ref.get(ref), (fibers) => fibers.size > 0 ? Fiber.joinAll(fibers) : Effect.void)
267
314
  )
268
315
  ), executionStrategy)
269
316
  }
@@ -355,7 +402,7 @@ export function tupleSink<A extends ReadonlyArray<any>, E, R, B, E2, R2>(
355
402
  if (values.size === expected) {
356
403
  return sink.onSuccess(getValues())
357
404
  } else {
358
- return Effect.unit
405
+ return Effect.void
359
406
  }
360
407
  })
361
408
  })
@@ -385,7 +432,7 @@ export function withDebounceFork<A, E, R>(
385
432
  ),
386
433
  () =>
387
434
  SynchronizedRef.get(ref).pipe(Effect.flatMap(Option.match({
388
- onNone: () => Effect.unit,
435
+ onNone: () => Effect.void,
389
436
  onSome: Fiber.join
390
437
  })))
391
438
  )
@@ -422,7 +469,7 @@ export class RingBuffer<A> {
422
469
  ) {
423
470
  switch (this._size) {
424
471
  case 0:
425
- return Effect.unit
472
+ return Effect.void
426
473
  case 1:
427
474
  return f(this._buffer[0], 0)
428
475
  case 2:
@@ -451,7 +498,7 @@ export class RingBuffer<A> {
451
498
 
452
499
  export function awaitScopeClose(scope: Scope.Scope) {
453
500
  return Effect.asyncEffect<unknown, never, never, never, never, never>((cb) =>
454
- Scope.addFinalizerExit(scope, () => Effect.sync(() => cb(Effect.unit)))
501
+ Scope.addFinalizerExit(scope, () => Effect.sync(() => cb(Effect.void)))
455
502
  )
456
503
  }
457
504
 
@@ -484,7 +531,7 @@ export class MulticastEffect<A, E, R> extends Effectable.Class<A, E, R> {
484
531
  if (this._fiber) {
485
532
  return Fiber.interruptFork(this._fiber)
486
533
  } else {
487
- return Effect.unit
534
+ return Effect.void
488
535
  }
489
536
  })
490
537
  }
@@ -1,6 +1,11 @@
1
- import type { FiberId } from "effect"
2
- import { Context, Effect, ExecutionStrategy, Exit, Option, Scope } from "effect"
3
- import type { Fx, KeyedOptions } from "../Fx.js"
1
+ import * as Context from "effect/Context"
2
+ import * as Effect from "effect/Effect"
3
+ import * as ExecutionStrategy from "effect/ExecutionStrategy"
4
+ import * as Exit from "effect/Exit"
5
+ import type * as FiberId from "effect/FiberId"
6
+ import * as Option from "effect/Option"
7
+ import * as Scope from "effect/Scope"
8
+ import { type Fx, type KeyedOptions } from "../Fx.js"
4
9
  import * as RefSubject from "../RefSubject.js"
5
10
  import * as Sink from "../Sink.js"
6
11
  import type { Add, Moved, Remove, Update } from "./diff.js"
@@ -64,46 +69,47 @@ function runKeyed<A, E, R, B extends PropertyKey, C, E2, R2, R3>(
64
69
  const scheduleNextEmit = forkDebounce(Effect.suspend(() => sink.onSuccess(getReadyIndices(state))))
65
70
 
66
71
  function diffAndPatch(values: ReadonlyArray<A>) {
67
- return Effect.gen(function*(_) {
72
+ return Effect.gen(function*() {
68
73
  const previous = state.previousValues
69
74
  state.previousValues = values
70
75
 
71
76
  let added = false
72
- let done = false
73
77
  let scheduled = false
78
+ let done = false
74
79
 
75
80
  for (const patch of diffIterator(previous, values, options)) {
76
81
  if (patch._tag === "Remove") {
77
- yield* _(removeValue(state, patch))
82
+ yield* removeValue(state, patch)
78
83
  } else if (patch._tag === "Add") {
79
84
  added = true
80
- yield* _(
81
- addValue(
82
- state,
83
- values,
84
- patch,
85
- id,
86
- parentScope,
87
- options,
88
- sink,
89
- Effect.suspend(() => {
90
- if (done === false) {
91
- scheduled = true
92
- return Effect.unit
93
- }
94
- return scheduleNextEmit
95
- })
96
- )
85
+ yield* addValue(
86
+ state,
87
+ values,
88
+ patch,
89
+ id,
90
+ parentScope,
91
+ options,
92
+ sink,
93
+ Effect.suspend(() => {
94
+ if (done === false) {
95
+ scheduled = true
96
+ return Effect.void
97
+ }
98
+ return scheduleNextEmit
99
+ })
97
100
  )
98
101
  } else {
99
- yield* _(updateValue(state, values, patch))
102
+ yield* updateValue(state, values, patch)
100
103
  }
101
104
  }
102
105
 
103
106
  done = true
104
107
 
105
108
  if (scheduled || added === false) {
106
- yield* _(scheduleNextEmit)
109
+ yield* scheduleNextEmit
110
+ } else {
111
+ // Allow fibers to begin running if we're adding Fibers
112
+ yield* Effect.sleep(1)
107
113
  }
108
114
  })
109
115
  }
@@ -117,7 +123,7 @@ function runKeyed<A, E, R, B extends PropertyKey, C, E2, R2, R3>(
117
123
  )
118
124
  )
119
125
  },
120
- options.debounce || 0
126
+ options.debounce || 1
121
127
  )
122
128
  }
123
129
 
@@ -162,16 +168,17 @@ function addValue<A, B extends PropertyKey, C, R2, E2, E, R3, D>(
162
168
  sink: Sink.Sink<ReadonlyArray<C>, E | E2, R2 | R3>,
163
169
  scheduleNextEmit: Effect.Effect<D, never, R3>
164
170
  ) {
165
- return Effect.gen(function*(_) {
171
+ return Effect.gen(function*() {
166
172
  const value = values[patch.index]
167
- const childScope = yield* _(Scope.fork(parentScope, ExecutionStrategy.sequential))
168
- const ref: RefSubject.RefSubject<A> = yield* _(RefSubject.unsafeMake<never, A>({
173
+ const childScope = yield* Scope.fork(parentScope, ExecutionStrategy.sequential)
174
+ const ref: RefSubject.RefSubject<A> = yield* RefSubject.unsafeMake<never, A>({
169
175
  initial: Effect.sync(() => entry.value),
170
176
  initialValue: value,
171
177
  scope: childScope,
172
178
  id
173
- }))
174
- yield* _(Scope.addFinalizer(childScope, ref.interrupt))
179
+ })
180
+
181
+ yield* Scope.addFinalizer(childScope, ref.interrupt)
175
182
 
176
183
  const entry = new KeyedEntry<A, C>(
177
184
  value,
@@ -184,18 +191,16 @@ function addValue<A, B extends PropertyKey, C, R2, E2, E, R3, D>(
184
191
  entries.set(patch.key, entry)
185
192
  indices.set(patch.index, patch.key)
186
193
 
187
- yield* _(
188
- Effect.forkIn(
189
- options.onValue(ref, patch.key).run(Sink.make(
190
- (cause) => sink.onFailure(cause),
191
- (output) => {
192
- entry.output = Option.some(output)
194
+ yield* Effect.forkIn(
195
+ options.onValue(ref, patch.key).run(Sink.make(
196
+ (cause) => sink.onFailure(cause),
197
+ (output) => {
198
+ entry.output = Option.some(output)
193
199
 
194
- return scheduleNextEmit
195
- }
196
- )),
197
- parentScope
198
- )
200
+ return scheduleNextEmit
201
+ }
202
+ )),
203
+ parentScope
199
204
  )
200
205
  })
201
206
  }
@@ -1,4 +1,4 @@
1
- import type { Either } from "effect"
1
+ import type * as Either from "effect/Either"
2
2
  import * as Option from "effect/Option"
3
3
  import * as Sink from "../Sink.js"
4
4
  import type { Bounds } from "./bounds.js"
@@ -1,4 +1,4 @@
1
- import type { Effect } from "effect"
1
+ import type * as Effect from "effect/Effect"
2
2
  import * as Effectable from "effect/Effectable"
3
3
  import { identity } from "effect/Function"
4
4
  import { pipeArguments } from "effect/Pipeable"
@@ -1,13 +1,12 @@
1
- import { ExecutionStrategy, type Scope } from "effect"
2
1
  import * as Effect from "effect/Effect"
3
2
  import * as Fiber from "effect/Fiber"
4
3
  import { dual } from "effect/Function"
5
4
  import * as MutableRef from "effect/MutableRef"
6
5
  import * as Option from "effect/Option"
6
+ import type * as Scope from "effect/Scope"
7
7
  import type { Fx } from "../Fx.js"
8
8
  import type { Sink } from "../Sink.js"
9
9
  import * as Subject from "../Subject.js"
10
- import { withScopedFork } from "./helpers.js"
11
10
  import { FxBase } from "./protos.js"
12
11
 
13
12
  export function share<A, E, R, R2>(
@@ -41,23 +40,17 @@ export class Share<A, E, R, R2> extends FxBase<A, E, R | R2 | Scope.Scope> {
41
40
  }
42
41
 
43
42
  run<R3>(sink: Sink<A, E, R3>): Effect.Effect<unknown, never, R | R2 | R3 | Scope.Scope> {
44
- return withScopedFork(
45
- (fork) =>
46
- Effect.flatMap(
47
- fork(
48
- Effect.onExit(this.i1.run(sink), () => this._RefCount.decrement() === 0 ? this.interrupt() : Effect.unit)
49
- ),
50
- () => this.initialize()
51
- ),
52
- ExecutionStrategy.sequential
43
+ return Effect.zipRight(
44
+ this.initialize(),
45
+ Effect.onExit(this.i1.run(sink), () => this._RefCount.decrement() === 0 ? this.interrupt() : Effect.void)
53
46
  )
54
47
  }
55
48
 
56
49
  private initialize(): Effect.Effect<unknown, never, R | R2> {
57
- return Effect.suspend(() => {
50
+ return Effect.suspend((): Effect.Effect<unknown, never, R | R2> => {
58
51
  if (this._RefCount.increment() === 1) {
59
52
  return this.i0.run(this.i1).pipe(
60
- Effect.onExit(() =>
53
+ Effect.ensuring(
61
54
  Effect.suspend(() => {
62
55
  MutableRef.set(this._FxFiber, Option.none())
63
56
  return this.i1.interrupt
@@ -65,26 +58,18 @@ export class Share<A, E, R, R2> extends FxBase<A, E, R | R2 | Scope.Scope> {
65
58
  ),
66
59
  Effect.interruptible,
67
60
  Effect.forkDaemon,
68
- Effect.tap((fiber) => Effect.sync(() => MutableRef.set(this._FxFiber, Option.some(fiber)))),
69
- Effect.flatMap(Fiber.join)
61
+ Effect.tap((fiber) => Effect.sync(() => MutableRef.set(this._FxFiber, Option.some(fiber))))
70
62
  )
71
63
  } else {
72
- return Option.match(
73
- MutableRef.get(this._FxFiber),
74
- {
75
- onNone: () => Effect.unit,
76
- onSome: Fiber.join
77
- }
78
- )
64
+ return Effect.void
79
65
  }
80
66
  })
81
67
  }
82
68
 
83
69
  private interrupt(): Effect.Effect<void, never, R | R2> {
84
- return Effect.suspend(() => {
85
- const fiber = Option.getOrNull(MutableRef.getAndSet(this._FxFiber, Option.none()))
86
-
87
- return fiber ? Effect.zip(Fiber.interrupt(fiber), this.i1.interrupt) : this.i1.interrupt
70
+ return Option.match(MutableRef.getAndSet(this._FxFiber, Option.none()), {
71
+ onNone: () => Effect.void,
72
+ onSome: Fiber.interrupt
88
73
  })
89
74
  }
90
75
  }
@@ -1,4 +1,4 @@
1
- import * as ReadonlyArray from "effect/ReadonlyArray"
1
+ import * as ReadonlyArray from "effect/Array"
2
2
 
3
3
  import * as Effect from "effect/Effect"
4
4
  import { flow } from "effect/Function"
@@ -95,11 +95,11 @@ export function compileCauseSyncOperatorSink<R>(
95
95
  ): Sink.Sink<any, any, R> {
96
96
  return matchSyncOperator(operator, {
97
97
  Map: (op) => Sink.make((a) => sink.onFailure(op.f(a)), sink.onSuccess),
98
- Filter: (op) => Sink.make((a) => op.f(a) ? sink.onFailure(a) : Effect.unit, sink.onSuccess),
98
+ Filter: (op) => Sink.make((a) => op.f(a) ? sink.onFailure(a) : Effect.void, sink.onSuccess),
99
99
  FilterMap: (op) =>
100
100
  Sink.make((a) =>
101
101
  Option.match(op.f(a), {
102
- onNone: () => Effect.unit,
102
+ onNone: () => Effect.void,
103
103
  onSome: sink.onFailure
104
104
  }), sink.onSuccess)
105
105
  })
@@ -1,4 +1,6 @@
1
- import { Effect, Option, ReadonlyArray } from "effect"
1
+ import * as Array from "effect/Array"
2
+ import * as Effect from "effect/Effect"
3
+ import * as Option from "effect/Option"
2
4
  import type { Sink } from "../Sink.js"
3
5
 
4
6
  const DISCARD = { discard: true } as const
@@ -65,8 +67,8 @@ export function runReduce<A, B>(
65
67
  return matchSyncProducer(producer, {
66
68
  Success: (a) => syncOnce(() => f(initial, a)),
67
69
  FromSync: (a) => syncOnce(() => f(initial, a())),
68
- FromArray: (a) => syncOnce(() => ReadonlyArray.reduce(a, initial, f)),
69
- FromIterable: (a) => syncOnce(() => ReadonlyArray.reduce(a, initial, f))
70
+ FromArray: (a) => syncOnce(() => Array.reduce(a, initial, f)),
71
+ FromIterable: (a) => syncOnce(() => Array.reduce(a, initial, f))
70
72
  })
71
73
  }
72
74
 
@@ -84,7 +86,7 @@ export function runReduceEffect<A, B, E2, R2>(
84
86
  }
85
87
 
86
88
  function arrayToSink<A, R2>(array: ReadonlyArray<A>, sink: Sink<A, never, R2>): Effect.Effect<unknown, never, R2> {
87
- if (array.length === 0) return Effect.unit
89
+ if (array.length === 0) return Effect.void
88
90
  else if (array.length === 1) return sink.onSuccess(array[0])
89
91
  else {
90
92
  const [first, ...rest] = array
@@ -97,7 +99,7 @@ function arrayToSink<A, R2>(array: ReadonlyArray<A>, sink: Sink<A, never, R2>):
97
99
  }
98
100
 
99
101
  function iterableToSink<A, R2>(array: Iterable<A>, sink: Sink<A, never, R2>): Effect.Effect<unknown, never, R2> {
100
- let effect: Effect.Effect<any, never, R2> = Effect.unit
102
+ let effect: Effect.Effect<any, never, R2> = Effect.void
101
103
 
102
104
  for (const item of array) {
103
105
  effect = Effect.zipRight(effect, sink.onSuccess(item))
@@ -37,7 +37,7 @@ function runWithKey<A, E, R, B extends PropertyKey, C, E2, R2, R3>(
37
37
  const run = fx.run(Sink.make(
38
38
  (cause) => sink.onFailure(cause),
39
39
  (value) =>
40
- Effect.gen(function*(_) {
40
+ Effect.gen(function*() {
41
41
  const key = options.getKey(value)
42
42
 
43
43
  // We don't need to do anything if the key is the same as the previous one
@@ -47,15 +47,15 @@ function runWithKey<A, E, R, B extends PropertyKey, C, E2, R2, R3>(
47
47
  // If the key is the same, we just need to update the value
48
48
  if (prev.key === key) {
49
49
  prev.value = value
50
- yield* _(RefSubject.set(prev.ref, value))
50
+ yield* RefSubject.set(prev.ref, value)
51
51
  return
52
52
  } else {
53
53
  // Otherwise, we need to remove the previous value
54
- yield* _(prev.ref.interrupt)
54
+ yield* prev.ref.interrupt
55
55
  }
56
56
  }
57
57
 
58
- const ref = yield* _(RefSubject.fromEffect(Effect.sync(() => state.value)))
58
+ const ref = yield* RefSubject.fromEffect(Effect.sync(() => state.value))
59
59
 
60
60
  // Create a new state
61
61
  const state: WithKeyState<A, B> = {
@@ -67,11 +67,11 @@ function runWithKey<A, E, R, B extends PropertyKey, C, E2, R2, R3>(
67
67
  previous = Option.some(state)
68
68
 
69
69
  // Create a new listener
70
- yield* _(fork(options.onValue(state.ref, state.key).run(sink)))
70
+ yield* fork(options.onValue(state.ref, state.key).run(sink))
71
71
  })
72
72
  ))
73
73
 
74
- return Effect.flatMap(run, () => Option.isSome(previous) ? previous.value.ref.interrupt : Effect.unit)
74
+ return Effect.flatMap(run, () => Option.isSome(previous) ? previous.value.ref.interrupt : Effect.void)
75
75
  }, ExecutionStrategy.sequential)
76
76
  }
77
77