asyncWithProgress

fun <T> CoroutineScope.asyncWithProgress(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend ProgressScope.() -> T): ProgressFuture<T>

Starts a coroutine like async and returns a ProgressFuture that reports its progress.

The block runs with a ProgressScope receiver, so it can report progress and slice the bar. On success, progress is completed to fraction = 1f, keeping the last phase. On failure or cancellation, progress freezes at the last reported value. context and start behave as in async.

val opening: ProgressFuture<PdfDocument> = scope.asyncWithProgress {
val header = slice(0.05f, "header")
val xref = slice(0.25f, "xref")
val pages = slice(0.70f, "pages")
header.report(1f)
val table = parseXref(xref)
loadPages(table) { done, total -> pages.report(done, total) }
}
opening.progress.collect { ui.show(it) } // or collectAsState() in Compose
val doc = opening.await()