Simulate a bounded response stream: deliver chunks to a slow consumer, record drops, and stop cleanly on cancellation.
Required APIdef stream_with_backpressure(chunks, capacity, consume_per_tick, cancel_after=None):
return {'delivered': [...], 'dropped': [...], 'peak_buffer': ..., 'cancelled': ...}BehaviorThink through the mechanism first if you want the extra reasoning step. It never blocks the editor.
stream_with_backpressure(['a', 'b'], 1, 1)a consumer keeping up sees every chunk
stream_with_backpressure(['a', 'b', 'c'], 1, 0)bounded buffers turn overload into visible backpressure
2 hidden edge tests run after the visible contract passes.
Run Tests to see the contract verdicts here.