Must use unlimited channels to avoid blocking the OkHttp threads.

This commit is contained in:
Vitor Pamplona
2025-10-02 17:46:35 -04:00
parent b83ea61522
commit f901f8ab8f
2 changed files with 4 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO import kotlinx.coroutines.IO
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.withTimeoutOrNull
@@ -46,7 +47,7 @@ suspend fun INostrClient.sendAndWaitForResponse(
relayList: Set<NormalizedRelayUrl>, relayList: Set<NormalizedRelayUrl>,
timeoutInSeconds: Long = 15, timeoutInSeconds: Long = 15,
): Boolean { ): Boolean {
val resultChannel = Channel<Result>() val resultChannel = Channel<Result>(UNLIMITED)
Log.d("sendAndWaitForResponse", "Waiting for ${relayList.size} responses") Log.d("sendAndWaitForResponse", "Waiting for ${relayList.size} responses")

View File

@@ -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.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.withTimeoutOrNull
suspend fun INostrClient.downloadFirstEvent( suspend fun INostrClient.downloadFirstEvent(
@@ -67,7 +68,7 @@ suspend fun INostrClient.downloadFirstEvent(
subscriptionId: String = newSubId(), subscriptionId: String = newSubId(),
filters: Map<NormalizedRelayUrl, List<Filter>>, filters: Map<NormalizedRelayUrl, List<Filter>>,
): Event? { ): Event? {
val resultChannel = Channel<Event>() val resultChannel = Channel<Event>(UNLIMITED)
val listener = val listener =
object : IRelayClientListener { object : IRelayClientListener {