@typed/fx 1.27.3 → 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 +27 -22
  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 +29 -20
  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 +55 -39
  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
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,10 +99,10 @@ 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
+ return Effect.asVoid(Effect.matchCauseEffect(f(earlyExit), {
105
106
  onFailure: (cause) => sink.onFailure(cause),
106
107
  onSuccess: () => earlyExit.earlyExit
107
108
  }))
@@ -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
  }
@@ -1019,7 +1020,7 @@ class FromTag<I, S, B, E2, R2> implements Sink<B, E2, I | R2> {
1019
1020
  */
1020
1021
  export function ignoreInterrupt<A, E, R>(sink: Sink<A, E, R>): Sink<A, E, R> {
1021
1022
  return make(
1022
- (cause) => Cause.isInterruptedOnly(cause) ? Effect.unit : sink.onFailure(cause),
1023
+ (cause) => Cause.isInterruptedOnly(cause) ? Effect.void : sink.onFailure(cause),
1023
1024
  sink.onSuccess
1024
1025
  )
1025
1026
  }
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"
@@ -78,8 +80,7 @@ const DISCARD = { discard: true } as const
78
80
  * @internal
79
81
  */
80
82
  export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subject<A, E> {
81
- protected sinks: Set<readonly [Sink<A, E, any>, Context.Context<any>]> = new Set()
82
- protected scopes: Set<Scope.CloseableScope> = new Set()
83
+ protected sinks: Set<readonly [Sink<A, E, any>, Context.Context<any>, Scope.CloseableScope]> = new Set()
83
84
 
84
85
  constructor() {
85
86
  super()
@@ -101,16 +102,12 @@ export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subj
101
102
  return this.onEvent(a)
102
103
  }
103
104
 
104
- readonly interrupt = Effect.fiberIdWith((id) =>
105
- Effect.tap(
106
- Effect.forEach(this.scopes, (scope) => Scope.close(scope, Exit.interrupt(id)), DISCARD),
107
- () => {
108
- this.sinks.clear()
109
- this.scopes.clear()
110
- }
111
- )
105
+ protected interruptScopes = Effect.fiberIdWith((id) =>
106
+ Effect.forEach(Array.from(this.sinks), ([, , scope]) => Scope.close(scope, Exit.interrupt(id)), DISCARD)
112
107
  )
113
108
 
109
+ readonly interrupt = this.interruptScopes
110
+
114
111
  protected addSink<R, B, R2>(
115
112
  sink: Sink<A, E, R>,
116
113
  f: (scope: Scope.Scope) => Effect.Effect<B, never, R2>
@@ -118,19 +115,13 @@ export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subj
118
115
  return withScope(
119
116
  (innerScope) =>
120
117
  Effect.contextWithEffect((ctx) => {
121
- const entry = [sink, ctx] as const
122
- const add = Effect.sync(() => {
123
- this.sinks.add(entry)
124
- this.scopes.add(innerScope)
125
- })
126
- const remove = Effect.sync(() => {
127
- this.sinks.delete(entry)
128
- this.scopes.delete(innerScope)
129
- })
118
+ const entry = [sink, ctx, innerScope] as const
119
+ this.sinks.add(entry)
120
+ const remove = Effect.sync(() => this.sinks.delete(entry))
130
121
 
131
122
  return Effect.zipRight(
132
123
  Scope.addFinalizer(innerScope, remove),
133
- Effect.zipRight(add, f(innerScope))
124
+ f(innerScope)
134
125
  )
135
126
  }),
136
127
  ExecutionStrategy.sequential
@@ -140,21 +131,50 @@ export class SubjectImpl<A, E> extends FxBase<A, E, Scope.Scope> implements Subj
140
131
  readonly subscriberCount: Effect.Effect<number> = Effect.sync(() => this.sinks.size)
141
132
 
142
133
  protected onEvent(a: A) {
143
- if (this.sinks.size === 0) return Effect.unit
144
- else {
145
- return Effect.forEach(this.sinks, ([sink, ctx]) => Effect.provide(sink.onSuccess(a), ctx), DISCARD)
134
+ if (this.sinks.size === 0) return Effect.void
135
+ else if (this.sinks.size === 1) {
136
+ const [sink, ctx] = this.sinks.values().next().value
137
+ return runSinkEvent(sink, ctx, a)
138
+ } else {
139
+ return Effect.forEach(
140
+ this.sinks,
141
+ ([sink, ctx]) => runSinkEvent(sink, ctx, a),
142
+ DISCARD
143
+ )
146
144
  }
147
145
  }
148
146
 
149
147
  protected onCause(cause: Cause.Cause<E>) {
150
- return Effect.forEach(
151
- this.sinks,
152
- ([sink, ctx]) => Effect.provide(sink.onFailure(cause), ctx),
153
- DISCARD
154
- )
148
+ if (this.sinks.size === 0) return Effect.void
149
+ else if (this.sinks.size === 1) {
150
+ const [sink, ctx, scope] = this.sinks.values().next().value
151
+ return runSinkCause(sink, ctx, scope, cause)
152
+ } else {
153
+ return Effect.forEach(
154
+ this.sinks,
155
+ ([sink, ctx, scope]) => runSinkCause(sink, ctx, scope, cause),
156
+ DISCARD
157
+ )
158
+ }
155
159
  }
156
160
  }
157
161
 
162
+ function runSinkEvent<A, E>(sink: Sink<A, E, any>, ctx: Context.Context<any>, a: A) {
163
+ return Effect.provide(Effect.catchAllCause(sink.onSuccess(a), sink.onFailure), ctx)
164
+ }
165
+
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
+ )
176
+ }
177
+
158
178
  /**
159
179
  * @internal
160
180
  */
@@ -185,11 +205,9 @@ export class HoldSubjectImpl<A, E> extends SubjectImpl<A, E> implements Subject<
185
205
  }))
186
206
  }
187
207
 
188
- readonly interrupt = Effect.fiberIdWith((id) =>
189
- Effect.tap(
190
- Effect.forEach(this.scopes, (scope) => Scope.close(scope, Exit.interrupt(id)), DISCARD),
191
- () => MutableRef.set(this.lastValue, Option.none())
192
- )
208
+ readonly interrupt = Effect.tap(
209
+ this.interruptScopes,
210
+ () => MutableRef.set(this.lastValue, Option.none())
193
211
  )
194
212
  }
195
213
 
@@ -216,11 +234,9 @@ export class ReplaySubjectImpl<A, E> extends SubjectImpl<A, E> {
216
234
  )
217
235
  }
218
236
 
219
- readonly interrupt = Effect.fiberIdWith((id) =>
220
- Effect.tap(
221
- Effect.forEach(this.scopes, (scope) => Scope.close(scope, Exit.interrupt(id)), DISCARD),
222
- () => this.buffer.clear()
223
- )
237
+ readonly interrupt = Effect.tap(
238
+ this.interruptScopes,
239
+ () => this.buffer.clear()
224
240
  )
225
241
  }
226
242
 
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
  }