@typed/fx 1.27.4 → 1.29.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 +38 -23
  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 +72 -43
  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 +4 -4
  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 +37 -23
  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 +71 -38
  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 +49 -30
  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 +93 -62
  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
package/src/Sink.ts CHANGED
@@ -4,13 +4,14 @@
4
4
  */
5
5
 
6
6
  import * as C from "@typed/context"
7
- import type { Predicate, Tracer } from "effect"
8
7
  import * as Cause from "effect/Cause"
9
8
  import * as Clock from "effect/Clock"
10
9
  import * as Effect from "effect/Effect"
11
10
  import { dual } from "effect/Function"
12
11
  import * as Layer from "effect/Layer"
13
12
  import * as Option from "effect/Option"
13
+ import type * as Predicate from "effect/Predicate"
14
+ import type * as Tracer from "effect/Tracer"
14
15
  import { type Bounds } from "./internal/bounds.js"
15
16
 
16
17
  /**
@@ -98,13 +99,13 @@ export function withEarlyExit<A, E, R, B, R2>(
98
99
  return Effect.asyncEffect((resume: (effect: Effect.Effect<void>) => void) => {
99
100
  const earlyExit: WithEarlyExit<A, E, R> = {
100
101
  ...sink,
101
- earlyExit: Effect.sync(() => resume(Effect.unit))
102
+ earlyExit: Effect.sync(() => resume(Effect.void))
102
103
  }
103
104
 
104
- return Effect.asUnit(Effect.matchCauseEffect(f(earlyExit), {
105
- onFailure: (cause) => sink.onFailure(cause),
105
+ return Effect.matchCauseEffect(f(earlyExit), {
106
+ onFailure: (cause) => Effect.asVoid(sink.onFailure(cause)),
106
107
  onSuccess: () => earlyExit.earlyExit
107
- }))
108
+ })
108
109
  })
109
110
  }
110
111
 
@@ -163,7 +164,7 @@ class FilterSink<A, E, R> implements Sink<A, E, R> {
163
164
 
164
165
  onSuccess(value: A) {
165
166
  if (this.predicate(value)) return this.sink.onSuccess(value)
166
- else return Effect.unit
167
+ else return Effect.void
167
168
  }
168
169
  }
169
170
 
@@ -190,7 +191,7 @@ class FilterMapSink<A, E, R, B> implements Sink<A, E, R> {
190
191
  onSuccess(value: A) {
191
192
  const option = this.f(value)
192
193
  if (Option.isSome(option)) return this.sink.onSuccess(option.value)
193
- else return Effect.unit
194
+ else return Effect.void
194
195
  }
195
196
  }
196
197
 
@@ -264,7 +265,7 @@ class FilterMapEffectSink<A, E, R, B, E2, R2> implements Sink<B, E2, R | R2> {
264
265
  onFailure: (cause) => this.sink.onFailure(cause),
265
266
  onSuccess: (option) => {
266
267
  if (Option.isSome(option)) return this.sink.onSuccess(option.value)
267
- else return Effect.unit
268
+ else return Effect.void
268
269
  }
269
270
  })
270
271
  }
@@ -303,7 +304,7 @@ class FilterEffectSink<A, E, R> implements Sink<A, E, R> {
303
304
  onFailure: (cause) => this.sink.onFailure(cause),
304
305
  onSuccess: (b) => {
305
306
  if (b) return this.sink.onSuccess(value)
306
- else return Effect.unit
307
+ else return Effect.void
307
308
  }
308
309
  })
309
310
  }
@@ -457,7 +458,7 @@ class FilterMapLoopSink<A, E, R, B, C> implements Sink<A, E, R> {
457
458
  const [option, acc] = this.f(this.seed, value)
458
459
  this.seed = acc
459
460
  if (Option.isSome(option)) return this.sink.onSuccess(option.value)
460
- else return Effect.unit
461
+ else return Effect.void
461
462
  }
462
463
  }
463
464
 
@@ -495,7 +496,7 @@ class FilterMapLoopCauseSink<A, E, R, B, C> implements Sink<A, E, R> {
495
496
  const [option, acc] = this.f(this.seed, cause)
496
497
  this.seed = acc
497
498
  if (Option.isSome(option)) return this.sink.onFailure(option.value)
498
- else return Effect.unit
499
+ else return Effect.void
499
500
  }
500
501
 
501
502
  onSuccess(value: A) {
@@ -588,7 +589,7 @@ class FilterMapLoopEffectSink<A, E, R, B, R2, C> implements Sink<A, E, R | R2> {
588
589
  onSuccess: ([option, acc]) => {
589
590
  this.seed = acc
590
591
  if (Option.isSome(option)) return this.sink.onSuccess(option.value)
591
- else return Effect.unit
592
+ else return Effect.void
592
593
  }
593
594
  })
594
595
  }
@@ -669,7 +670,7 @@ class FilterMapLoopCauseEffectSink<A, E, R, B, E2, R2, C> implements Sink<A, E,
669
670
  onSuccess: ([option, acc]) => {
670
671
  this.seed = acc
671
672
  if (Option.isSome(option)) return this.sink.onFailure(option.value)
672
- else return Effect.unit
673
+ else return Effect.void
673
674
  }
674
675
  })
675
676
  }
@@ -721,10 +722,10 @@ class SliceSink<A, E, R> implements Sink<A, E, R> {
721
722
  onSuccess(value: A) {
722
723
  if (this.drop > 0) {
723
724
  this.drop--
724
- return Effect.unit
725
+ return Effect.void
725
726
  }
726
727
  if (this.take-- > 0) {
727
- return Effect.tap(this.sink.onSuccess(value), () => this.take === 0 ? this.sink.earlyExit : Effect.unit)
728
+ return Effect.tap(this.sink.onSuccess(value), () => this.take === 0 ? this.sink.earlyExit : Effect.void)
728
729
  }
729
730
  return this.sink.earlyExit
730
731
  }
@@ -794,25 +795,43 @@ export const dropWhile: {
794
795
  })
795
796
 
796
797
  /**
797
- * @since 1.20.0
798
+ * @since 2.0.0
798
799
  */
799
800
  export const dropAfter: {
800
- <A>(predicate: Predicate.Predicate<A>): <E, R>(
801
- sink: Sink<A, E, R>
802
- ) => Sink<A, E, R>
803
- <A, E, R>(sink: Sink<A, E, R>, predicate: Predicate.Predicate<A>): Sink<A, E, R>
804
- } = dual(2, function dropAfter<A, E, R>(
801
+ <A, E, R, R2>(
802
+ sink: Sink<A, E, R>,
803
+ predicate: Predicate.Predicate<A>,
804
+ f: (sink: Sink<A, E, R>) => Effect.Effect<unknown, E, R2>
805
+ ): Effect.Effect<void, never, R | R2>
806
+ } = dual(3, function dropAfter<A, E, R, R2>(
805
807
  sink: Sink<A, E, R>,
806
- predicate: Predicate.Predicate<A>
807
- ) {
808
- return filterMapLoop(sink, false, (drop: boolean, a: A) => {
809
- if (drop === true) return [Option.none(), drop]
810
-
811
- const drop2 = predicate(a)
812
- return [Option.some(a), drop2]
813
- })
808
+ predicate: Predicate.Predicate<A>,
809
+ f: (sink: Sink<A, E, R>) => Effect.Effect<unknown, E, R2>
810
+ ): Effect.Effect<void, never, R | R2> {
811
+ return withEarlyExit(sink, (s) => f(new DropAfterSink(s, predicate)))
814
812
  })
815
813
 
814
+ class DropAfterSink<A, E, R> implements Sink<A, E, R> {
815
+ constructor(
816
+ readonly sink: WithEarlyExit<A, E, R>,
817
+ readonly predicate: Predicate.Predicate<A>
818
+ ) {
819
+ this.onFailure = this.onFailure.bind(this)
820
+ this.onSuccess = this.onSuccess.bind(this)
821
+ }
822
+
823
+ onFailure(cause: Cause.Cause<E>): Effect.Effect<unknown, never, R> {
824
+ return this.sink.onFailure(cause)
825
+ }
826
+
827
+ onSuccess(value: A) {
828
+ if (this.predicate(value)) {
829
+ return Effect.zipRight(this.sink.onSuccess(value), this.sink.earlyExit)
830
+ }
831
+ return this.sink.onSuccess(value)
832
+ }
833
+ }
834
+
816
835
  /**
817
836
  * @since 1.20.0
818
837
  */
@@ -1019,7 +1038,7 @@ class FromTag<I, S, B, E2, R2> implements Sink<B, E2, I | R2> {
1019
1038
  */
1020
1039
  export function ignoreInterrupt<A, E, R>(sink: Sink<A, E, R>): Sink<A, E, R> {
1021
1040
  return make(
1022
- (cause) => Cause.isInterruptedOnly(cause) ? Effect.unit : sink.onFailure(cause),
1041
+ (cause) => Cause.isInterruptedOnly(cause) ? Effect.void : sink.onFailure(cause),
1023
1042
  sink.onSuccess
1024
1043
  )
1025
1044
  }
package/src/Subject.ts CHANGED
@@ -4,14 +4,16 @@
4
4
  */
5
5
 
6
6
  import * as C from "@typed/context"
7
- import type { Cause, Layer, Pipeable } from "effect"
7
+ import type * as Cause from "effect/Cause"
8
8
  import type * as Context from "effect/Context"
9
9
  import * as Effect from "effect/Effect"
10
10
  import * as ExecutionStrategy from "effect/ExecutionStrategy"
11
11
  import * as Exit from "effect/Exit"
12
12
  import { dual, identity } from "effect/Function"
13
+ import type * as Layer from "effect/Layer"
13
14
  import * as MutableRef from "effect/MutableRef"
14
15
  import * as Option from "effect/Option"
16
+ import type * as Pipeable from "effect/Pipeable"
15
17
  import { hasProperty } from "effect/Predicate"
16
18
  import * as Scope from "effect/Scope"
17
19
  import { type Fx } from "./Fx.js"
@@ -101,12 +103,7 @@ export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subj
101
103
  }
102
104
 
103
105
  protected interruptScopes = Effect.fiberIdWith((id) =>
104
- Effect.tap(
105
- Effect.forEach(this.sinks, ([, , scope]) => Scope.close(scope, Exit.interrupt(id)), DISCARD),
106
- () => {
107
- this.sinks.clear()
108
- }
109
- )
106
+ Effect.forEach(Array.from(this.sinks), ([, , scope]) => Scope.close(scope, Exit.interrupt(id)), DISCARD)
110
107
  )
111
108
 
112
109
  readonly interrupt = this.interruptScopes
@@ -134,7 +131,7 @@ export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subj
134
131
  readonly subscriberCount: Effect.Effect<number> = Effect.sync(() => this.sinks.size)
135
132
 
136
133
  protected onEvent(a: A) {
137
- if (this.sinks.size === 0) return Effect.unit
134
+ if (this.sinks.size === 0) return Effect.void
138
135
  else if (this.sinks.size === 1) {
139
136
  const [sink, ctx] = this.sinks.values().next().value
140
137
  return runSinkEvent(sink, ctx, a)
@@ -148,14 +145,14 @@ export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subj
148
145
  }
149
146
 
150
147
  protected onCause(cause: Cause.Cause<E>) {
151
- if (this.sinks.size === 0) return Effect.unit
148
+ if (this.sinks.size === 0) return Effect.void
152
149
  else if (this.sinks.size === 1) {
153
- const [sink, ctx] = this.sinks.values().next().value
154
- return runSinkCause(sink, ctx, cause)
150
+ const [sink, ctx, scope] = this.sinks.values().next().value
151
+ return runSinkCause(sink, ctx, scope, cause)
155
152
  } else {
156
153
  return Effect.forEach(
157
154
  this.sinks,
158
- ([sink, ctx]) => runSinkCause(sink, ctx, cause),
155
+ ([sink, ctx, scope]) => runSinkCause(sink, ctx, scope, cause),
159
156
  DISCARD
160
157
  )
161
158
  }
@@ -166,8 +163,16 @@ function runSinkEvent<A, E>(sink: Sink<A, E, any>, ctx: Context.Context<any>, a:
166
163
  return Effect.provide(Effect.catchAllCause(sink.onSuccess(a), sink.onFailure), ctx)
167
164
  }
168
165
 
169
- function runSinkCause<A, E>(sink: Sink<A, E, any>, ctx: Context.Context<any>, cause: Cause.Cause<E>) {
170
- return Effect.provide(Effect.catchAllCause(sink.onFailure(cause), () => Effect.unit), ctx)
166
+ function runSinkCause<A, E>(
167
+ sink: Sink<A, E, any>,
168
+ ctx: Context.Context<any>,
169
+ scope: Scope.CloseableScope,
170
+ cause: Cause.Cause<E>
171
+ ) {
172
+ return Effect.provide(
173
+ Effect.catchAllCause(sink.onFailure(cause), (error) => Scope.close(scope, Exit.failCause(error))),
174
+ ctx
175
+ )
171
176
  }
172
177
 
173
178
  /**
package/src/Versioned.ts CHANGED
@@ -6,12 +6,14 @@
6
6
  */
7
7
 
8
8
  import type * as Context from "@typed/context"
9
- import type { Layer, Runtime, Scope } from "effect"
10
- import { Exit } from "effect"
11
9
  import * as Effect from "effect/Effect"
10
+ import * as Exit from "effect/Exit"
12
11
  import { dual, flow } from "effect/Function"
12
+ import type * as Layer from "effect/Layer"
13
13
  import { sum } from "effect/Number"
14
14
  import * as Option from "effect/Option"
15
+ import type * as Runtime from "effect/Runtime"
16
+ import type * as Scope from "effect/Scope"
15
17
  import type { Fx } from "./Fx.js"
16
18
  import * as core from "./internal/core.js"
17
19
  import { MulticastEffect } from "./internal/helpers.js"
@@ -1,35 +1,41 @@
1
- import type { Equivalence, FiberId } from "effect"
1
+ import { MutableRef } from "effect"
2
2
  import * as Deferred from "effect/Deferred"
3
3
  import * as Effect from "effect/Effect"
4
+ import type * as Equivalence from "effect/Equivalence"
4
5
  import * as Exit from "effect/Exit"
6
+ import type * as FiberId from "effect/FiberId"
5
7
  import * as Option from "effect/Option"
6
8
  import { EffectBase } from "./protos.js"
7
9
 
8
10
  export class DeferredRef<E, A> extends EffectBase<A, E, never> {
9
11
  // Keep track of the latest value emitted by the stream
10
- public current!: Option.Option<Exit.Exit<A, E>>
11
12
  public version!: number
12
13
  public deferred!: Deferred.Deferred<A, E>
13
14
 
14
- constructor(private id: FiberId.FiberId, private eq: Equivalence.Equivalence<Exit.Exit<A, E>>) {
15
+ constructor(
16
+ private id: FiberId.FiberId,
17
+ private eq: Equivalence.Equivalence<Exit.Exit<A, E>>,
18
+ readonly current: MutableRef.MutableRef<Option.Option<Exit.Exit<A, E>>>
19
+ ) {
15
20
  super()
16
21
  this.reset()
17
22
  }
18
23
 
19
24
  toEffect() {
20
25
  return Effect.suspend(() => {
21
- if (Option.isNone(this.current)) {
26
+ const current = MutableRef.get(this.current)
27
+ if (Option.isNone(current)) {
22
28
  return Deferred.await(this.deferred)
23
29
  } else {
24
- return this.current.value
30
+ return current.value
25
31
  }
26
32
  })
27
33
  }
28
34
 
29
35
  done(exit: Exit.Exit<A, E>) {
30
- const current = this.current
36
+ const current = MutableRef.get(this.current)
31
37
 
32
- this.current = Option.some(exit)
38
+ MutableRef.set(this.current, Option.some(exit))
33
39
 
34
40
  if (Option.isSome(current) && this.eq(current.value, exit)) {
35
41
  return false
@@ -42,7 +48,7 @@ export class DeferredRef<E, A> extends EffectBase<A, E, never> {
42
48
  }
43
49
 
44
50
  reset() {
45
- this.current = Option.none()
51
+ MutableRef.set(this.current, Option.none())
46
52
  this.version = -1
47
53
 
48
54
  if (this.deferred) {
@@ -54,9 +60,13 @@ export class DeferredRef<E, A> extends EffectBase<A, E, never> {
54
60
  }
55
61
 
56
62
  export function make<E, A>(eq: Equivalence.Equivalence<Exit.Exit<A, E>>) {
57
- return Effect.map(Effect.fiberId, (id) => new DeferredRef(id, eq))
63
+ return Effect.map(Effect.fiberId, (id) => new DeferredRef(id, eq, MutableRef.make(Option.none())))
58
64
  }
59
65
 
60
- export function unsafeMake<E, A>(id: FiberId.FiberId, eq: Equivalence.Equivalence<Exit.Exit<A, E>>) {
61
- return new DeferredRef(id, eq)
66
+ export function unsafeMake<E, A>(
67
+ id: FiberId.FiberId,
68
+ eq: Equivalence.Equivalence<Exit.Exit<A, E>>,
69
+ current: MutableRef.MutableRef<Option.Option<Exit.Exit<A, E>>>
70
+ ) {
71
+ return new DeferredRef(id, eq, current)
62
72
  }