mapProgressTo
suspend fun <R> mapProgressTo(progressInterval: ClosedFloatingPointRange<Double>, block: suspend () -> R): R(source)
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))
}
Content copied to clipboard
Loading(0%)
Loading(50%)
Loading(50%)
Loading(75%)
Loading(100%)
Content copied to clipboard
See also
Equivalent without coroutines
Transform progress events arbitrarily instead of only reducing their interval