Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-streams-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Reserve queue capacity for termination signals in `Stream.asyncPush` with bounded dropping or sliding buffers.
4 changes: 2 additions & 2 deletions packages/effect/src/internal/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,9 @@ const queueFromBufferOptionsPush = <A, E>(
}
switch (options?.strategy) {
case "sliding":
return Queue.sliding(options.bufferSize ?? 16)
return Queue.sliding((options.bufferSize ?? 16) + 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this just delays the problem rather than fixing it

default:
return Queue.dropping(options?.bufferSize ?? 16)
return Queue.dropping((options?.bufferSize ?? 16) + 1)
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/effect/test/Stream/async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,21 @@ describe("Stream", () => {
assertTrue(Chunk.isEmpty(result))
}))

for (const strategy of ["dropping", "sliding"] as const) {
it.effect(`asyncPush - signals the end with a bounded ${strategy} buffer`, () =>
Effect.gen(function*() {
const result = yield* Stream.asyncPush<number>((emit) => {
emit.single(42)
emit.end()
return Effect.void
}, { bufferSize: 1, strategy }).pipe(
Stream.runCollect,
Effect.timeout("1 second")
)
deepStrictEqual(Array.from(result), [42])
}))
}

it.effect("asyncPush - handles errors", () =>
Effect.gen(function*() {
const error = new Cause.RuntimeException("boom")
Expand Down