Package-level declarations

Types

Link copied to clipboard

ForegroundJobRegistry that ignores interactions and returns a completed Job on consume.

Link copied to clipboard

Provides LocalClosureContainer that ignores local changes and returns closure.

Link copied to clipboard
class DispatchCoroutineScope(coroutineScope: CoroutineScope) : DispatchClosure.Element, CoroutineScope

Default CoroutineScope associated with a store. By default, the store contains a MainScope and it can be replaced at store creation by adding it into a DispatchClosure. It can be accessed by coroutineScope extension property. Tools provided by this library most likely use this scope to launch a coroutine.

Link copied to clipboard

A ForegroundJobRegistry that ignores registered job and always fails on consume. It's injected by default into the store's closure.

Link copied to clipboard
@ObjCName(name = "ReduKtForegroundJobAction", exact = true)
interface ForegroundJobAction : Action

Marker interface for every Action that has a foreground job (kotlinx.coroutines.Job) logically associated with it.This kind of action must result in a single coroutine being launched by a middleware using launchForeground. Handle to this coroutine is returned by dispatchJob or it might be simply joined using joinDispatchJob. CoroutineScope depends on method used to dispatch it.

Link copied to clipboard

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.

Link copied to clipboard

A ForegroundJobRegistry that allows to register only one Job at once. Repeated call to a register without a consumeOrNull results in an exception.

Functions

Link copied to clipboard

Dispatches action and expects any middleware to launch a single foreground job logically associate with it. Coroutine is launched in a scope provided by DispatchCoroutineScope.

Link copied to clipboard
fun DispatchScope<*>.dispatchJobIn(action: ForegroundJobAction, scope: CoroutineScope): Job

Dispatches action and expects any middleware to launch a single foreground job logically associate with it. Coroutine is launched in the scope.

Link copied to clipboard

Dispatches action and expects any middleware to launch a single foreground job logically associate with it. This function suspends until foreground job is finished. When coroutine that calls this function is cancelled, foreground job is also cancelled.

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.

fun MiddlewareScope<*>.launchForeground(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job

Launches a foreground job using closure form this scope. 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
fun Flow<*>.launchInForegroundOf(scope: MiddlewareScope<*>): Job

Launches a foreground coroutine to collect this flow using given scope.

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

Returns a DispatchClosure that enables foreground coroutines mechanism.

Link copied to clipboard

Creates a DispatchClosure that skips coroutines mechanism. Every dispatchJob is executed with no failure and returns completed job.

Link copied to clipboard
fun DispatchScope<*>.synchronized(block: suspend DispatchScope<*>.() -> Unit): Job

Runs given block as a coroutine in DispatchScope.coroutineScope. Effectively it ensures that any operation on a DispatchScope inside a block runs on proper thread.

Properties

Link copied to clipboard
val DispatchScope<*>.coroutineScope: CoroutineScope

Returns CoroutineScope associated with a store.