Makes sure subscriptions are closed on the NostrClient utility methods
This commit is contained in:
+5
-2
@@ -65,15 +65,18 @@ suspend fun INostrClient.queryCountSuspend(
|
||||
|
||||
subscribe(listener)
|
||||
|
||||
val result =
|
||||
try {
|
||||
queryCount(subId = subId, filters = mapOf(relay to listOf(filter)))
|
||||
|
||||
val result =
|
||||
withTimeoutOrNull(timeoutMs) {
|
||||
resultChannel.receive()
|
||||
}
|
||||
|
||||
} finally {
|
||||
close(subId)
|
||||
unsubscribe(listener)
|
||||
}
|
||||
|
||||
resultChannel.close()
|
||||
|
||||
return result
|
||||
|
||||
+5
-2
@@ -98,6 +98,8 @@ suspend fun INostrClient.sendAndWaitForResponseDetailed(
|
||||
}
|
||||
}
|
||||
|
||||
val receivedResults =
|
||||
try {
|
||||
subscribe(subscription)
|
||||
|
||||
// subscribe before sending the result.
|
||||
@@ -126,9 +128,10 @@ suspend fun INostrClient.sendAndWaitForResponseDetailed(
|
||||
result
|
||||
}
|
||||
|
||||
val receivedResults = resultSubscription.await()
|
||||
|
||||
resultSubscription.await()
|
||||
} finally {
|
||||
unsubscribe(subscription)
|
||||
}
|
||||
|
||||
// Clean up the channel
|
||||
resultChannel.close()
|
||||
|
||||
+4
-2
@@ -104,14 +104,16 @@ suspend fun INostrClient.downloadFirstEvent(
|
||||
}
|
||||
}
|
||||
|
||||
val result =
|
||||
try {
|
||||
openReqSubscription(subscriptionId, filters, listener)
|
||||
|
||||
val result =
|
||||
withTimeoutOrNull(30000) {
|
||||
resultChannel.receive()
|
||||
}
|
||||
|
||||
} finally {
|
||||
close(subscriptionId)
|
||||
}
|
||||
|
||||
resultChannel.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user