/claim #9810
Fixes #9810.
This PR fixes an off by one behavior in ZStream.buffer(capacity) where buffer(n) allowed n + 1 elements in flight.
capacity <= 0
No-op. Returns the original stream unchanged.
capacity == 1
Uses a synchronous ZStream.Handoff path so exactly one element is buffered ahead.
capacity >= 2
Uses internal queue size capacity - 1 so queue capacity plus one in-flight element equals exactly capacity.
buffer(1) buffers exactly 1 elementbuffer(2) buffers exactly 2 elementsbuffer(0) is a no-opThese tests use Promise coordination to make assertions deterministic.
sbt "-Dsbt.supershell=false" "streamsTestsJVM/testOnly zio.stream.ZStreamSpec -- -t buffer"sbt "-Dsbt.supershell=false" "streamsTestsJS/testOnly zio.stream.ZStreamSpec -- -t buffer"sbt "-Dsbt.supershell=false" "streamsTestsNative/testOnly zio.stream.ZStreamSpec -- -t buffer"Result:
23 tests passed, 0 failed, 0 ignored on each platform run.
https://github.com/user-attachments/assets/d789aecb-7644-4812-851d-1b1975bc0125
Demo video attached showing:
saurabh
@SaurabhCodesAI
ZIO
@ZIO