I need to sync data when a FCM push message is received. My whole infrastructure used coroutines. From the looks of it seems that I need a runBlocking, however I'd best like to avoid that, sync my Syncer exposes only regular functions and uses it's own coroutine scope to run suspend functions
class SomeSyncer {
private val scope = CoroutineScope ..
private val _state = MutableFlow...
val state: Flow<State> get() = _state
fun sync() {
scope.launch {
_state.value = RUNNING
doSync()
_state.value = IDLE
}
}
}
class FcmService : FirebaseMessageingService {
override onMessageReceived() {
someSyncer.sync() ?
or
runBlocking {
someSyncer.sync() ..somehow make it wait? maybe the lowercase coroutineScope?
}
}
}
- Is runBlocking necessary?
- Can I still run in my custom scope but have the runBlocking work somehow, without refactoring?
- What if I just use the 1st variant and sideffect to custom scope, will I break wakelocks? (sync is like 1-2seconds max)
- Or should I expose a suspend function public api (which I don't really want to, it's never needed unless here)