refactor: unify db refresh flows
This commit is contained in:
@@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
@@ -45,6 +46,14 @@ fun <T> Flow<T>.listenValue(
|
||||
action: suspend (T) -> Unit
|
||||
): Job = onEach(action::invoke).launchIn(coroutineScope)
|
||||
|
||||
fun CoroutineScope.launchDbRefresh(
|
||||
load: suspend () -> Unit,
|
||||
after: suspend () -> Unit
|
||||
): Job = launch {
|
||||
load()
|
||||
after()
|
||||
}
|
||||
|
||||
fun createTimerFlow(
|
||||
time: Int,
|
||||
onStartAction: (suspend () -> Unit)? = null,
|
||||
|
||||
Reference in New Issue
Block a user