with Progress
Joins a Deferred and a progress flow that you already have into one ProgressFuture.
Use it for an API that reports progress through a callback, such as a Ktor download with onDownload.
val state = MutableStateFlow(Progress(null, "downloading"))
val download = scope.async {
client.get(url) {
onDownload { sent, total ->
val fraction = total?.let { sent.toFloat() / it }
state.value = Progress(fraction, "downloading")
}
}.body<ByteArray>()
}.withProgress(state)Content copied to clipboard
Watch out
This function never changes progress. Unlike asyncWithProgress, it does not set
1fon success. Your own code sets every value.
Parameters
progress
the flow that ProgressFuture.progress returns, unchanged.