Handling FiberSet Finalization and Error Propagation in Effect.gen

I have a FiberSet within an Effect.gen.

const root = Effect.gen(function*() {
  const fibers = yield* FiberSet.make<void, E>()
  // ...
}).pipe(
  Effect.scoped
)


I populate this FiberSet with a Stream.fromQueue.

  // ...
  const dequeue = yield* pubsub.subscribe
  yield* Stream.fromQueue(dequeue).pipe(
    Stream.runForEach(f),
    FiberSet.run(fibers),
  )
  // ...


When the Scope is closed, I want the pubsub to stop listening. However, I don't want thefibers to be killed.

It initially seemed I could add a finalizer to await the fiberset. Ie.

  yield* Effect.addFinalizer(() => FiberSet.join(fibers))


Unfortunately, finalizer effects cannot contain error / this wouldn't propagate errors within fibers to root. Ideally, the E of f-produced effects would be represented in root.

Any tips on how to ensure the fibers are all resolved / stop the completed parent fiber from terminating fibers?
Was this page helpful?