Skip to content

Commit

Permalink
don't hold the lock while emitting
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 28, 2024
1 parent 8704620 commit f6e8124
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/main/scala/util/Batcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ final class Batcher[Key, Elem, Batch](
if newBuffer.counter >= maxBatchSize then emitAndRemove(key)

private def emitAndRemove(key: Key): Unit =
buffers.computeIfPresent(
key,
(_, buffer) =>
buffer.cancel()
emit(key, buffer.batch)
null
)
Option(buffers.remove(key)).foreach: buffer =>
buffer.cancel()
emit(key, buffer.batch)

0 comments on commit f6e8124

Please sign in to comment.