From 04adcace913e6fc483df266874a68005e9e04ccf Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 12 Aug 2024 12:53:51 +1200 Subject: [PATCH] ensure Stream.toReadableStream pulls always result in a enqueue (#3444) --- .changeset/soft-cows-beam.md | 5 +++++ packages/effect/src/internal/stream.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/soft-cows-beam.md diff --git a/.changeset/soft-cows-beam.md b/.changeset/soft-cows-beam.md new file mode 100644 index 0000000000..a478d224ba --- /dev/null +++ b/.changeset/soft-cows-beam.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +ensure Stream.toReadableStream pulls always result in a enqueue diff --git a/packages/effect/src/internal/stream.ts b/packages/effect/src/internal/stream.ts index 9d28dab7f9..459827d6bc 100644 --- a/packages/effect/src/internal/stream.ts +++ b/packages/effect/src/internal/stream.ts @@ -6895,10 +6895,14 @@ export const toReadableStreamRuntime = dual< return new ReadableStream({ start(controller) { scope = runSync(Scope.make()) - pull = pipe( + const pullChunk: Effect.Effect, Option.Option, R> = pipe( toPull(self), Scope.extend(scope), runSync, + Effect.flatMap((chunk) => Chunk.isEmpty(chunk) ? pullChunk : Effect.succeed(chunk)) + ) + pull = pipe( + pullChunk, Effect.tap((chunk) => Effect.sync(() => { Chunk.map(chunk, (a) => {