mapProgressTo¶
suspend fun <R> mapProgressTo(progressInterval: ClosedFloatingPointRange<Double>, block: suspend () -> R): R
Reduces progress events emitted in block to fit into progressInterval.
Example¶
suspend fun main() {
reportProgress(::println) {
mapProgressTo(0.0..0.5) {
task1()
}
mapProgressTo(0.5..1.0) {
task2()
}
}
}
suspend fun task1() {
report(loading(0.0))
delay(500)
report(loading(1.0))
}
suspend fun task2() {
report(loading(0.0))
delay(500)
report(loading(0.5))
delay(500)
report(loading(1.0))
}
See also¶
-
reduceToInterval: Equivalent without coroutines -
transformProgress: Transform progress events arbitrarily instead of only reducing their interval