Skip to content

Commit

Permalink
Refactored/improved while loop inside AtomicExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Oct 17, 2024
1 parent 0596e88 commit 6009d6c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions chat-android/src/main/java/com/ably/chat/AtomicExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class AtomicExecutor(private val scope: CoroutineScope) {
scope.launch {
if (!isRunning) {
isRunning = true
while (priorityQueue.size > 0) {
val task = priorityQueue.remove()
val result = kotlin.runCatching { scope.async(block = task.coroutineBlock).await() }
task.resultChannel.send(result)
while (priorityQueue.isNotEmpty()) {
val task = priorityQueue.poll()
task?.let {
val result = kotlin.runCatching { scope.async(block = it.coroutineBlock).await() }
it.resultChannel.send(result)
}
}
isRunning = false
}
Expand Down

0 comments on commit 6009d6c

Please sign in to comment.