Skip to content

Commit

Permalink
Improve queue processing efficiency. (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laimiux authored May 16, 2024
1 parent 0aa73d7 commit 438cad9
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class SynchronizedUpdateQueue(
val peekUpdate = updateQueue.peek()
if (peekUpdate != null) {
// Since there is a pending update, we try to process it.
val updateExecuted = takeOver(this::pollAndExecute)
if (!updateExecuted) {
val executed = takeOver(this::executeQueue)
if (!executed) {
return
}
} else {
Expand All @@ -95,10 +95,12 @@ class SynchronizedUpdateQueue(
}
}

private fun pollAndExecute() {
// We remove first update from the queue and execute if it exists.
val actualUpdate = updateQueue.poll()
actualUpdate?.invoke()
private fun executeQueue() {
var update = updateQueue.poll()
while (update != null) {
update()
update = updateQueue.poll()
}
}

/**
Expand Down

0 comments on commit 438cad9

Please sign in to comment.