Aleksei V
02/13/2025, 6:42 PMpublic fun subscribe(requests: Flow<GeyserOuterClass.SubscribeRequest>, headers: Metadata =
Metadata()): Flow<GeyserOuterClass.SubscribeUpdate>
val reqFlow = MutableStateFlow(
subscribeRequest {}
)
// Subscribing
client.subscribe(reqFlow).catch { e ->
println("Flow exception: ${e.message}")
}.collect {
handle(it, "message")
}
// Pinger to send periodic requests
private fun startPinger(subscription: MutableStateFlow<SubscribeRequest>): Job {
var counter = 0
return CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO> + SupervisorJob()).launch {
try {
while (isActive) {
subscription.update {
SubscribeRequest.newBuilder()
.setPing(
GeyserOuterClass.SubscribeRequestPing.newBuilder()
.setId(counter++)
.build()
)
.build()
}
delay(10000)
}
} catch (e: Exception) {
<http://logger.info|logger.info>("Pinger stopped")
}
}
}
The issue: The first request from reqFlow is not sent. How can fix it, or may be some another way?uli
02/17/2025, 9:09 AMCoroutineScope(<http://Dispatchers.IO|Dispatchers.IO> + SupervisorJob())
as otherwise it can be garbage collected if all coroutines are suspended.uli
02/17/2025, 9:15 AMuli
02/17/2025, 9:16 AMwhile (isActive) {
uli
02/17/2025, 9:23 AMemit
suspend until there is a receiver.
https://kotlinlang.org/docs/flow.html#bufferinguli
02/18/2025, 7:44 AMuli
02/18/2025, 7:45 AM