Issue with Stream Sharing and Multiple Consumers in Effect Typescript

Hi guys, I'm trying to share a stream using Stream.share, but only the first consumer of my stream is getting values. Any ideas?

const sharedChangeStream = yield* listenStream(vscode.workspace.onDidChangeTextDocument).pipe(
    Stream.share({ capacity: "unbounded" }),
  )

  yield* sharedChangeStream.pipe(
    Stream.debounce("200 millis"),
    Stream.runForEach(() => Effect.log("First one")),
    Effect.forkScoped,
  )

  yield* sharedChangeStream.pipe(
    Stream.debounce("2 seconds"),
    Stream.runForEach(() => Effect.log("Second one one")),
    Effect.forkScoped,
  )


listenStream (vscode.ts)::
export const listenStream = <A>(event: vscode.Event<A>): Stream.Stream<A> =>
  Stream.async<A>(emit => {
    const d = event(data => emit.single(data))
    return Effect.sync(() => {
      d.dispose()
    })
  })


How can I make it so that I get two streams of the same changes, but with different debounces before running the effects?
Was this page helpful?