abbic
01/10/2024, 3:25 PMCasey Brooks
01/10/2024, 3:37 PMpublic class JobRunner(private val coroutineScope: CoroutineScope) {
private val _count = MutableStateFlow(0)
public val count get() = _count.asStateFlow()
public fun launchInBackground(block: suspend () -> Unit) {
val job = coroutineScope.launch {
_count.update { it + 1 }
block()
}
job.invokeOnCompletion {
_count.update { it - 1 }
}
}
}
abbic
01/10/2024, 3:40 PM