ForegroundJobRegistry

Allows to register a foreground job. It is responsible for passing Job reference outside the store, so it can be awaited or cancelled. By default, the store contains EmptyForegroundJobRegistry inside its closure. Functions like dispatchJob use local closure mechanism to replace it with SingleForegroundJobRegistry. launchForeground directly refers to local ForegroundJobRegistry.

Types

Link copied to clipboard

Functions

Link copied to clipboard
abstract fun consume(): Job

Returns registered foreground job or throws.

Link copied to clipboard
abstract fun consumeOrNull(): Job?

Returns registered foreground job or null.

Link copied to clipboard
open override fun <T : DispatchClosure.Element> find(key: DispatchClosure.Key<T>): T?

Returns Element associated with the key or null.

Link copied to clipboard
open operator override fun <T : DispatchClosure.Element> get(key: DispatchClosure.Key<T>): T

Returns Element associated with the key or throws MissingClosureElementException.

Link copied to clipboard
open operator override fun minus(key: DispatchClosure.Key<*>): DispatchClosure

Returns a closure without the element with a given key

Link copied to clipboard
open operator fun plus(closure: DispatchClosure): DispatchClosure

Combines this closure with incoming closure. If both closures contain elements with the same keys, the ones from the incoming closure remain.

Link copied to clipboard
abstract fun register(job: Job)

Registers a foreground job.

Link copied to clipboard

Returns elements form this DispatchClosure as a Map.

Properties

Link copied to clipboard
open override val key: ForegroundJobRegistry.Key

Key of this element.

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
Link copied to clipboard
fun DispatchClosure.launchForeground(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job

Launches a foreground job using this closure. By default, it's launched in a scope provided by DispatchCoroutineScope. This behaviour might be changed by dispatchJobIn or joinDispatchJob. Because this function uses local closure, calling it outside dispatch should not be done, because it might result in unexpected behaviour.

Link copied to clipboard

Returns this closure with local changes.

Link copied to clipboard
inline fun DispatchClosure.registeringJob(closure: DispatchClosure = EmptyDispatchClosure, newFrame: Boolean = false, block: DispatchClosure.() -> Unit): Job

Runs block that must register a foreground job. It adds SingleForegroundJobRegistry to local closure to allow proper job registration. Local closure change creates a new frame if newFrame is true.

Link copied to clipboard
inline fun <T> DispatchClosure.withLocalClosure(closure: DispatchClosure, newFrame: Boolean = false, block: DispatchClosure.() -> T): T

Changes LocalClosureContainer with a given closure for a time of block execution.