Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve queue processing efficiency. #369

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading