Skip to content

Commit a3a6698

Browse files
Fix flaky bufferByCountAndTime: reset window when buffer transitions from empty
When an item arrives into an empty buffer, the remaining time (rt - delta) could be near-zero if the item arrived just before the timer fired. This caused a Sleep(~0ms) timer in the next iteration, which could expire before the next item arrived on a loaded CI machine. Fix: when the first item enters the buffer (count goes 0→1), start a fresh timeoutMs window. The timer window should measure how long items have been accumulating, not track time from when the buffer was last cleared. Fixes the flaky AsyncSeq.bufferByTimeAndCount test. Co-authored-by: Copilot <[email protected]>
1 parent 1e78834 commit a3a6698

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,10 @@ module AsyncSeq =
22772277
buffer.Clear()
22782278
yield! loop None timeoutMs
22792279
else
2280-
yield! loop None (rt - delta)
2280+
// When the first item arrives into an empty buffer, start a fresh window.
2281+
// Otherwise, track remaining time in the current window.
2282+
let nextRt = if buffer.Count = 1 then timeoutMs else rt - delta
2283+
yield! loop None nextRt
22812284
| Choice2Of2 (_, rest) ->
22822285
if buffer.Count > 0 then
22832286
yield buffer.ToArray()

0 commit comments

Comments
 (0)