From f9a4742dd322ba06590c46c3c0cb81fb27326163 Mon Sep 17 00:00:00 2001 From: Laimonas Turauskas Date: Thu, 16 May 2024 13:36:13 -0400 Subject: [PATCH] Improve queue processing efficiency. --- .../formula/internal/SynchronizedUpdateQueue.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/formula/src/main/java/com/instacart/formula/internal/SynchronizedUpdateQueue.kt b/formula/src/main/java/com/instacart/formula/internal/SynchronizedUpdateQueue.kt index 93aef0d2..6ce90225 100644 --- a/formula/src/main/java/com/instacart/formula/internal/SynchronizedUpdateQueue.kt +++ b/formula/src/main/java/com/instacart/formula/internal/SynchronizedUpdateQueue.kt @@ -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 { @@ -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() + } } /**