Package dispatch.core

Types

Link copied to clipboard
interface DefaultCoroutineScope : CoroutineScope

Marker interface which designates a CoroutineScope with a CoroutineDispatcher of default.

Link copied to clipboard
object DefaultDispatcherProvider

Holder singleton for a DispatcherProvider instance.

Link copied to clipboard
interface DispatcherProvider : CoroutineContext.Element

Interface corresponding to the different CoroutineDispatcher's offered by Dispatchers.

Link copied to clipboard
interface IOCoroutineScope : CoroutineScope

Marker interface which designates a CoroutineScope with a CoroutineDispatcher of io.

Link copied to clipboard
interface MainCoroutineScope : CoroutineScope

Marker interface which designates a CoroutineScope with a CoroutineDispatcher of main.

Link copied to clipboard
interface MainImmediateCoroutineScope : CoroutineScope

Marker interface which designates a CoroutineScope with a CoroutineDispatcher of mainImmediate.

Link copied to clipboard
interface UnconfinedCoroutineScope : CoroutineScope

Marker interface which designates a CoroutineScope with a CoroutineDispatcher of unconfined.

Functions

Link copied to clipboard
fun <T> CoroutineScope.asyncDefault(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred.

Link copied to clipboard
fun <T> CoroutineScope.asyncIO(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred.

Link copied to clipboard
fun <T> CoroutineScope.asyncMain(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred.

Link copied to clipboard
fun <T> CoroutineScope.asyncMainImmediate(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred.

Link copied to clipboard
fun <T> CoroutineScope.asyncUnconfined(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred.

Link copied to clipboard
fun DefaultCoroutineScope(coroutineContext: CoroutineContext): DefaultCoroutineScope
fun DefaultCoroutineScope(job: Job = SupervisorJob(), dispatcherProvider: DispatcherProvider = DefaultDispatcherProvider.get()): DefaultCoroutineScope

Factory function for a DefaultCoroutineScope with a DispatcherProvider. Dispatch defaults to the default property of the DispatcherProvider.

Link copied to clipboard
fun DispatcherProvider(): DispatcherProvider
fun DispatcherProvider(default: CoroutineDispatcher, io: CoroutineDispatcher, main: CoroutineDispatcher, mainImmediate: CoroutineDispatcher, unconfined: CoroutineDispatcher): DispatcherProvider

Default implementation of DispatcherProvider which simply delegates to the corresponding properties in the Dispatchers singleton.

Link copied to clipboard
fun <T> Flow<T>.flowOnDefault(): Flow<T>

Extracts the DispatcherProvider from the coroutineContext of the collector coroutine, then uses its DispatcherProvider.default property to call flowOn(theDispatcher), and returns the result.

Link copied to clipboard
fun <T> Flow<T>.flowOnIO(): Flow<T>

Extracts the DispatcherProvider from the coroutineContext of the collector coroutine, then uses its DispatcherProvider.io property to call flowOn(theDispatcher), and returns the result.

Link copied to clipboard
fun <T> Flow<T>.flowOnMain(): Flow<T>

Extracts the DispatcherProvider from the coroutineContext of the collector coroutine, then uses its DispatcherProvider.main property to call flowOn(theDispatcher), and returns the result.

Link copied to clipboard
fun <T> Flow<T>.flowOnMainImmediate(): Flow<T>

Extracts the DispatcherProvider from the coroutineContext of the collector coroutine, then uses its DispatcherProvider.mainImmediate property to call flowOn(theDispatcher), and returns the result.

Link copied to clipboard
fun <T> Flow<T>.flowOnUnconfined(): Flow<T>

Extracts the DispatcherProvider from the coroutineContext of the collector coroutine, then uses its DispatcherProvider.unconfined property to call flowOn(theDispatcher), and returns the result.

Link copied to clipboard
fun IOCoroutineScope(coroutineContext: CoroutineContext): IOCoroutineScope

Factory function for a IOCoroutineScope with a DispatcherProvider. Dispatch defaults to the io property of the DispatcherProvider.

fun IOCoroutineScope(job: Job = SupervisorJob(), dispatcherProvider: DispatcherProvider = DefaultDispatcherProvider.get()): IOCoroutineScope

Factory function for an IOCoroutineScope with a DispatcherProvider. Dispatch defaults to the io property of the DispatcherProvider.

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

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

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

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

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

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

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

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

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

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

Link copied to clipboard
fun MainCoroutineScope(coroutineContext: CoroutineContext): MainCoroutineScope
fun MainCoroutineScope(job: Job = SupervisorJob(), dispatcherProvider: DispatcherProvider = DefaultDispatcherProvider.get()): MainCoroutineScope

Factory function for a MainCoroutineScope with a DispatcherProvider. Dispatch defaults to the main property of the DispatcherProvider.

Link copied to clipboard
fun MainImmediateCoroutineScope(coroutineContext: CoroutineContext): MainImmediateCoroutineScope
fun MainImmediateCoroutineScope(job: Job = SupervisorJob(), dispatcherProvider: DispatcherProvider = DefaultDispatcherProvider.get()): MainImmediateCoroutineScope

Factory function for a MainImmediateCoroutineScope with a DispatcherProvider. Dispatch defaults to the mainImmediate property of the DispatcherProvider.

Link copied to clipboard
fun UnconfinedCoroutineScope(coroutineContext: CoroutineContext): UnconfinedCoroutineScope
fun UnconfinedCoroutineScope(job: Job = SupervisorJob(), dispatcherProvider: DispatcherProvider = DefaultDispatcherProvider.get()): UnconfinedCoroutineScope

Factory function for a UnconfinedCoroutineScope with a DispatcherProvider. Dispatch defaults to the unconfined property of the DispatcherProvider.

Link copied to clipboard
suspend fun <T> withDefault(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

Link copied to clipboard
suspend fun <T> withIO(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

Link copied to clipboard
suspend fun <T> withMain(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

Link copied to clipboard
suspend fun <T> withMainImmediate(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

Link copied to clipboard
suspend fun <T> withUnconfined(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

Properties

Link copied to clipboard
val CoroutineScope.defaultDispatcher: CoroutineDispatcher

Extracts the defaultCoroutineDispatcher out of the CoroutineScope, using DefaultDispatcherProvider.get to provide one if necessary.

Link copied to clipboard
val CoroutineScope.dispatcherProvider: DispatcherProvider

Extracts the DispatcherProvider out of the CoroutineScope, or returns a new instance of DefaultDispatcherProvider.get if the coroutineContext does not have one specified.

Link copied to clipboard

Extracts the DispatcherProvider out of the CoroutineContext, or returns a default from DefaultDispatcherProvider.get if the CoroutineContext does not have one specified.

Link copied to clipboard
val CoroutineScope.ioDispatcher: CoroutineDispatcher

Extracts the ioCoroutineDispatcher out of the CoroutineScope, using DefaultDispatcherProvider.get to provide one if necessary.

Link copied to clipboard
val CoroutineScope.mainDispatcher: CoroutineDispatcher

Extracts the mainCoroutineDispatcher out of the CoroutineScope, using DefaultDispatcherProvider.get to provide one if necessary.

Link copied to clipboard
val CoroutineScope.mainImmediateDispatcher: CoroutineDispatcher

Extracts the mainImmediateCoroutineDispatcher out of the CoroutineScope, using DefaultDispatcherProvider.get to provide one if necessary.

Link copied to clipboard
val CoroutineScope.unconfinedDispatcher: CoroutineDispatcher

Extracts the unconfinedCoroutineDispatcher out of the CoroutineScope, using DefaultDispatcherProvider.get to provide one if necessary.