Progress Future
A running operation that you can await, plus its live progress.
You get one from asyncWithProgress, or from withProgress for an operation that already has a progress flow. Use one per operation that the user sees, such as "open document" or "download file", not one per inner step.
val opening = scope.asyncWithProgress { loadDocument() }
launch { opening.progress.collect { bar.show(it.fraction, it.phase) } }
val document = opening.await()Content copied to clipboard
Compared with Deferred
A ProgressFuture is not a Deferred, because kotlinx-coroutines does not allow other classes to implement Deferred. await and cancel are here. For awaitAll, select or invokeOnCompletion, use deferred.
Watch out
progress keeps only the latest value. A slow collector skips reports. To limit UI updates, use a
Flowoperator such asprogress.sample(100.milliseconds).