Say you have a callback with some arguments that is called many times to notify an event. How would you translate it with coroutines? Is it better a ReceiveCannel
or a Flow
? How to implement both without some memory leak?
Here’s my usecase. I need to use Firebase for a project that is going multiplatform and I need a data structure available in common that is capable of handling callback registrations and removal.
For example how would you handle with a Flow
the authStateListener
?
actual val authStateFlow: Flow<Boolean>
get() = flow {
supervisorScope {
delegate.addAuthStateListener {
launch { emit(it.currentUser != null) }
}
}
}