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 0fed3c8d1..469136b41 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 @@ -91,25 +91,28 @@ suspend fun INostrClient.sendAndWaitForResponse( // subscribe before sending the result. val resultSubscription = coroutineScope { - async(Dispatchers.IO) { - val receivedResults = mutableMapOf() - // The withTimeout block will cancel the coroutine if the loop takes too long - withTimeoutOrNull(timeoutInSeconds * 1000) { - while (receivedResults.size < relayList.size) { - val result = resultChannel.receive() + val result = + async(Dispatchers.IO) { + val receivedResults = mutableMapOf() + // The withTimeout block will cancel the coroutine if the loop takes too long + withTimeoutOrNull(timeoutInSeconds * 1000) { + while (receivedResults.size < relayList.size) { + val result = resultChannel.receive() - val currentResult = receivedResults[result.relay] - // do not override a successful result. - if (currentResult == null || !currentResult) { - receivedResults.put(result.relay, result.success) + val currentResult = receivedResults[result.relay] + // do not override a successful result. + if (currentResult == null || !currentResult) { + receivedResults.put(result.relay, result.success) + } } } + receivedResults } - receivedResults - } - } - send(event, relayList) + send(event, relayList) + + result + } val receivedResults = resultSubscription.await()