This PR fixes issue #9810 by ensuring buffer(n) does not run more than n elements ahead of downstream:
For buffer(1): Use synchronous handoff with Promise to ensure exactly 1 element is buffered. The producer waits for the consumer to acknowledge receipt before producing the next element.
For buffer(n) where n > 1: Use queue of size n-1 (accounting for in-flight element)
For buffer(0) or negative: Keep original behavior
The fix uses and to maintain laziness of the capacity parameter, which is required for backward compatibility.
All 1136 tests pass, including:
Closes #9810 /claim #9810
tianlin-magi
@tele-he-gmail-com
ZIO
@ZIO