Fix permanent event batching for infinite buffers - #325
Conversation
| case :queue.peek(queue) do | ||
| {:value, {^infos, perm}} -> | ||
| {{:value, _}, queue} = :queue.out(queue) | ||
| take_permanents(queue, buffer - 1, infos, [perm | perms]) |
There was a problem hiding this comment.
Do we need to worry about buffer going eventually negative? Can we add a test or is it bound to the queue size anyway?
There was a problem hiding this comment.
I believe it is bounded by the queue size, since each permanent stored in the infinite buffer increments the count and the helper only decrements it when another permanent entry is actually present in the queue. I also added an assertion that the buffer count reaches 0 when all entries are consumed.
| {queue, buffer, perms} = | ||
| take_permanents(queue, buffer - 1, infos, [perm]) | ||
|
|
||
| {:ok, {queue, buffer, infos}, counter, :lists.reverse(temps), :lists.reverse(perms)} |
There was a problem hiding this comment.
What about the other clauses? Is this an issue:
When the last requested temporary event makes counter - 1 == 0, recursion enters the zero-counter clause before examining the following permanent entries and take_permanents/4 is never called:
buffer = Buffer.new(:infinity)
{buffer, _, _} = Buffer.store_temporary(buffer, [:temp], :first)
{:ok, buffer} = Buffer.store_permanent_unless_empty(buffer, :perm1)
{:ok, buffer} = Buffer.store_permanent_unless_empty(buffer, :perm2)
Buffer.take_count_or_until_permanent(buffer, 1)
#=> returns temps: [:temp], perms: [] and both permanents remain buffered
If so, we need to add a test for it.
There was a problem hiding this comment.
Yes, that was an issue. I added a regression test for this case and updated the infinite-buffer path to handle permanents when the counter reaches zero.
|
💚 💙 💜 💛 ❤️ |
Fixes the different behavior of
Buffer.take_count_or_until_permanent/2for infinite buffers.
Infinite buffers previously returned only the first permanent event.
This change collects consecutive permanent events, matching the behavior
of finite buffers.
Closes #317