ProgressFuture

interface ProgressFuture<out T> : Deferred<T>

A Deferred that also exposes live progress.

Every Deferred member works here: await(), cancel(), awaitAll(...), and onAwait. In addition, progress is a conflated StateFlow of the latest Progress, observable from Compose via progress.collectAsState().

Apply progress policy such as throttling or monotonic bars with a Flow operator, for example progress.sample(100.milliseconds).

Create one with asyncWithProgress, or adapt an existing pair with withProgress. The intended granularity is one ProgressFuture per user-visible operation such as opening a document or downloading a file, not per inner step.

Properties

Link copied to clipboard
abstract val children: Sequence<Job>
Link copied to clipboard
abstract val isActive: Boolean
Link copied to clipboard
abstract val isCancelled: Boolean
Link copied to clipboard
abstract val isCompleted: Boolean
Link copied to clipboard
abstract val key: CoroutineContext.Key<*>
Link copied to clipboard
abstract val onAwait: SelectClause1<T>
Link copied to clipboard
abstract val onJoin: SelectClause0
Link copied to clipboard
@ExperimentalCoroutinesApi
abstract val parent: Job?
Link copied to clipboard
abstract val progress: StateFlow<Progress>

Latest progress. Starts indeterminate; set to fraction = 1f on success.

Functions

Link copied to clipboard
@InternalCoroutinesApi
abstract fun attachChild(child: ChildJob): ChildHandle
Link copied to clipboard
abstract suspend fun await(): T
Link copied to clipboard
suspend fun <T> Deferred<T>.awaitOrDefault(timeout: Duration, default: T): T

Awaits this deferred value and returns default if timeout elapses first.

Link copied to clipboard
suspend fun <T> Deferred<T>.awaitOrNull(timeout: Duration): T?

Awaits this deferred value and returns null if timeout elapses first.

Link copied to clipboard
abstract fun cancel(cause: CancellationException?)
Link copied to clipboard
open override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R
Link copied to clipboard
open operator override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E?
Link copied to clipboard
@InternalCoroutinesApi
abstract fun getCancellationException(): CancellationException
Link copied to clipboard
@ExperimentalCoroutinesApi
abstract fun getCompleted(): T
Link copied to clipboard
@ExperimentalCoroutinesApi
abstract fun getCompletionExceptionOrNull(): Throwable?
Link copied to clipboard
abstract fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle
@InternalCoroutinesApi
abstract fun invokeOnCompletion(onCancelling: Boolean, invokeImmediately: Boolean, handler: CompletionHandler): DisposableHandle
Link copied to clipboard
abstract suspend fun join()
Link copied to clipboard
open override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext
Link copied to clipboard
open operator fun plus(context: CoroutineContext): CoroutineContext
open operator fun plus(other: Job): Job
Link copied to clipboard
abstract fun start(): Boolean
Link copied to clipboard
fun <T> Deferred<T>.withProgress(progress: StateFlow<Progress>): ProgressFuture<T>

Adapts an existing Deferred and an external progress StateFlow into a ProgressFuture.