Skip to content

feat: Add Bounded Queues With Backpressure Signaling - #10

Merged
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/backpressure
Sep 4, 2026
Merged

feat: Add Bounded Queues With Backpressure Signaling#10
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/backpressure

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

The work queue used to grow its ready list without a limit. Slow or missing consumers could pile up forever and the producer had no way to find out.

This adds a finite ready-queue capacity. enqueue throws QueueFullError when the backlog is full, and tryEnqueue returns { accepted: false } so a caller can wait. A WatermarkGate watches ready depth: pause at or above high, resume at or below low, hold the last state in the open band. Occupancy bouncing between high and high-1 only stays paused when low is at most high-2. Default bounds for capacity 2 are high=2 and low=1, so 2 vs 1 does flip. Redelivery of a message that already got in is still allowed to sit above capacity. Prefetch still caps in-flight.

Flow notifications run after the pump is idle so a listener throw on consume/ack is not swallowed by deliver's handler try/catch. enqueue can still throw a listener error after the payload is already on ready: treat that as notify-after-accept, not reject-and-retry.

Closes #9

Finite ready-queue capacity with reject-on-full, plus high/low
watermark hysteresis so producers can pause and resume without
dropping work the queue already accepted.
Sync ack still sits inside deliver's handler try/catch. Flow
notifications from that path were swallowed after the entry
settled. Defer applyFlow until pumping is false, and cover
the consume-drain listener throw.
@ThomasHartDev
ThomasHartDev force-pushed the thomas/feat/backpressure branch from 2da3eb2 to 7d4c200 Compare September 4, 2026 19:28
@ThomasHartDev
ThomasHartDev merged commit 318ad2e into main Sep 4, 2026
1 check passed
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/backpressure branch September 4, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bounded work-queue backlog with high/low watermark backpressure

1 participant