From f901f8ab8ffa1f50e203fe8ada5d8f86873ddebd Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 2 Oct 2025 17:46:35 -0400 Subject: [PATCH] Must use unlimited channels to avoid blocking the OkHttp threads. --- .../relay/client/accessories/NostrClientSendAndWaitExt.kt | 3 ++- .../relay/client/accessories/NostrClientSingleDownloadExt.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt index 469136b41..81344f075 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSendAndWaitExt.kt @@ -32,6 +32,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.withTimeoutOrNull @@ -46,7 +47,7 @@ suspend fun INostrClient.sendAndWaitForResponse( relayList: Set, timeoutInSeconds: Long = 15, ): Boolean { - val resultChannel = Channel() + val resultChannel = Channel(UNLIMITED) Log.d("sendAndWaitForResponse", "Waiting for ${relayList.size} responses") diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSingleDownloadExt.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSingleDownloadExt.kt index 7b2acdc17..cfcc7fe00 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSingleDownloadExt.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/accessories/NostrClientSingleDownloadExt.kt @@ -29,6 +29,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED import kotlinx.coroutines.withTimeoutOrNull suspend fun INostrClient.downloadFirstEvent( @@ -67,7 +68,7 @@ suspend fun INostrClient.downloadFirstEvent( subscriptionId: String = newSubId(), filters: Map>, ): Event? { - val resultChannel = Channel() + val resultChannel = Channel(UNLIMITED) val listener = object : IRelayClientListener {