@typed/fx 1.20.2 → 1.20.3

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/src/Fx.ts CHANGED
@@ -2382,9 +2382,9 @@ export const when: {
2382
2382
  /**
2383
2383
  * @since 1.20.0
2384
2384
  */
2385
- export const withEmitter = <E, A, R = never>(
2386
- f: (emitter: Emitter.Emitter<E, A>) => Effect.Effect<R, E, unknown>
2387
- ): Fx<R | Scope.Scope, E, A> => core.make<R | Scope.Scope, E, A>((sink) => Emitter.withEmitter(sink, f))
2385
+ export const withEmitter = <E, A, R = never, E2 = never>(
2386
+ f: (emitter: Emitter.Emitter<E, A>) => Effect.Effect<R, E2, unknown>
2387
+ ): Fx<R, E | E2, A> => core.make<R, E | E2, A>((sink) => Emitter.withEmitter(sink, f))
2388
2388
 
2389
2389
  /**
2390
2390
  * Create an Fx which will wait a specified duration of time where no
package/src/RefSubject.ts CHANGED
@@ -1432,7 +1432,7 @@ class RefSubjectTuple<
1432
1432
  ) {
1433
1433
  super()
1434
1434
 
1435
- this.versioned = Versioned.tuple(refs) as any
1435
+ this.versioned = Versioned.hold(Versioned.tuple(refs)) as any
1436
1436
  this.version = this.versioned.version
1437
1437
  this.interrupt = Effect.all(refs.map((r) => r.interrupt), UNBOUNDED)
1438
1438
  this.subscriberCount = Effect.map(
@@ -1588,7 +1588,7 @@ class RefSubjectStruct<
1588
1588
  ) {
1589
1589
  super()
1590
1590
 
1591
- this.versioned = Versioned.struct(refs) as any
1591
+ this.versioned = Versioned.hold(Versioned.struct(refs)) as any
1592
1592
  this.version = this.versioned.version
1593
1593
  this.interrupt = Effect.all(Object.values(refs).map((r) => r.interrupt), UNBOUNDED)
1594
1594
  this.subscriberCount = Effect.map(
package/src/Versioned.ts CHANGED
@@ -255,19 +255,10 @@ export function struct<const VS extends Readonly<Record<string, Versioned<any, a
255
255
  Effect.Effect.Error<VS[keyof VS]>,
256
256
  { readonly [K in keyof VS]: Effect.Effect.Success<VS[K]> }
257
257
  > {
258
- return map(
259
- tuple(
260
- Object.entries(versioneds).map(([k, v]) =>
261
- map(v, {
262
- onFx: (x) => [k, x] as const,
263
- onEffect: (x) => [k, x] as const
264
- })
265
- )
266
- ),
267
- {
268
- onFx: Object.fromEntries,
269
- onEffect: Object.fromEntries
270
- }
258
+ return make(
259
+ Effect.map(Effect.all(Object.values(versioneds).map((v) => v.version)), (versions) => versions.reduce(sum, 0)),
260
+ core.struct(versioneds),
261
+ Effect.all(versioneds, { concurrency: "unbounded" }) as any
271
262
  )
272
263
  }
273
264
 
@@ -7,6 +7,7 @@ import * as Effectable from "effect/Effectable"
7
7
  import * as Equal from "effect/Equal"
8
8
  import * as ExecutionStrategy from "effect/ExecutionStrategy"
9
9
  import * as Fiber from "effect/Fiber"
10
+ import * as FiberSet from "effect/FiberSet"
10
11
  import * as Option from "effect/Option"
11
12
  import * as Ref from "effect/Ref"
12
13
  import * as Scope from "effect/Scope"
@@ -225,31 +226,18 @@ export function withExhaustLatestFork<R, E, A>(
225
226
  }
226
227
 
227
228
  export function withUnboundedFork<R, E, A>(
228
- f: (fork: FxFork, scope: Scope.Scope) => Effect.Effect<R, E, A>,
229
- executionStrategy: ExecutionStrategy.ExecutionStrategy
229
+ f: (fork: FxFork, scope: Scope.Scope) => Effect.Effect<R, E, A>
230
230
  ) {
231
- return withScopedFork((fork, scope) =>
231
+ return Effect.scopeWith((scope) =>
232
232
  Effect.flatMap(
233
- Ref.make<Map<symbol, Fiber.Fiber<never, void>>>(new Map()),
234
- (ref) =>
233
+ FiberSet.make<never, void>(),
234
+ (set) =>
235
235
  Effect.flatMap(
236
- f((effect) => {
237
- const id = Symbol()
238
-
239
- return Effect.tap(
240
- fork(Effect.onExit(effect, () => Ref.update(ref, (map) => (map.delete(id), map)))),
241
- (fiber) => {
242
- if (Fiber.isRuntimeFiber(fiber)) {
243
- return Ref.update(ref, (map) => map.set(id, fiber))
244
- } else {
245
- return Effect.unit
246
- }
247
- }
248
- )
249
- }, scope),
250
- () => Effect.flatMap(Ref.get(ref), (fibers) => fibers.size > 0 ? Fiber.joinAll(fibers.values()) : Effect.unit)
236
+ f((effect) => FiberSet.run(set, effect), scope),
237
+ () => Fiber.joinAll(set)
251
238
  )
252
- ), executionStrategy)
239
+ )
240
+ )
253
241
  }
254
242
 
255
243
  export function withBoundedFork(capacity: number) {