From 4f019c6e491390e179ef0e9de878d41e622997a3 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 24 Nov 2025 10:01:05 -0500 Subject: [PATCH] Removes ConcurrentModificationException on outbox events --- .../relay/client/pool/PoolEventOutboxState.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolEventOutboxState.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolEventOutboxState.kt index 195c3f909..6f4088f60 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolEventOutboxState.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/PoolEventOutboxState.kt @@ -28,13 +28,13 @@ class PoolEventOutboxState( val event: Event, var relays: Set, ) { - private val tries = mutableMapOf() + private var tries = mapOf() fun updateRelays(newRelays: Set) { relays = newRelays } - fun isDone(url: NormalizedRelayUrl) = tries[url]?.let { it.isDone() } ?: false + fun isDone(url: NormalizedRelayUrl) = tries[url]?.isDone() ?: false fun isDone() = relays.all { isDone(it) } @@ -54,7 +54,7 @@ class PoolEventOutboxState( if (currentTries != null) { currentTries.tries.add(TimeUtils.now()) } else { - tries.put(url, Tries(mutableListOf(TimeUtils.now()))) + tries = tries + (url to Tries(mutableListOf(TimeUtils.now()))) } } @@ -67,12 +67,12 @@ class PoolEventOutboxState( if (currentTries != null) { currentTries.responses.add(Response(success, message)) } else { - tries.put( - url, - Tries( - mutableListOf(TimeUtils.now() - 1), - mutableListOf(Response(success, message)), - ), + tries = tries + ( + url to + Tries( + mutableListOf(TimeUtils.now() - 1), + mutableListOf(Response(success, message)), + ) ) } } @@ -82,7 +82,7 @@ class PoolEventOutboxState( val tries: MutableList = mutableListOf(), val responses: MutableList = mutableListOf(), ) { - fun isDone() = responses.any { it.success == true } || responses.size > 2 || tries.size > 3 + fun isDone() = responses.any { it.success } || responses.size > 2 || tries.size > 3 } class Response(