Dave Scheck
01/23/2024, 4:20 PMsuspend fun sendMessageAwaitResponse(
sendMessageFunc: suspend () -> Unit,
rxFlow: Flow<CustomMessage>,
responseType: Class<out CustomMessage>
): CustomMessage {
lateinit var response: CustomMessage
val jobs = listOf(
lifecycleScope.launch {
response = rxFlow.first { msg ->
msg.javaClass == msgTypeClass
}
},
lifecycleScope.launch {
sendMessageFunc()
},
)
jobs.joinAll()
return response
}
ross_a
01/23/2024, 4:38 PMsuspend fun awaitCallback(
sendMessageFunc: suspend () -> Unit,
rxFlow: Flow<CustomMessage>,
): CustomMessage {
val async = scope.async(start = CoroutineStart.UNDISPATCHED) {
rxFlow.first()
}
sendMessageFunc()
return async.await()
}
ross_a
01/23/2024, 4:39 PM.first()
before it resumes the outer block and calls sendMessageFunc()
Dave Scheck
01/23/2024, 6:27 PMbezrukov
01/23/2024, 6:36 PM