All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.StateFlowProgressReporter.kt Maven / Gradle / Ivy

The newest version!
package opensavvy.progress.coroutines

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import opensavvy.progress.Progress
import opensavvy.progress.loading
import opensavvy.progress.report.ProgressReporter

/**
 * [ProgressReporter] implementation which stores the latest progress information in [progress], a [StateFlow].
 */
class StateFlowProgressReporter : ProgressReporter {
    private val state = MutableStateFlow(loading(0.0))

    val progress = state as StateFlow

    override fun report(progress: Progress) {
        state.value = progress
    }

    override fun toString() = "StateFlowProgressReporter(progress=${progress.value})"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy