Companion

object Companion

The companion object provides utility functions for working with coroutines

Functions

Link copied to clipboard
inline fun launchOnDefault(crossinline block: suspend CoroutineScope.() -> Unit)

Launches a new coroutine on the Dispatchers.Default context and executes the given block.

Link copied to clipboard
inline fun launchOnIO(crossinline block: suspend CoroutineScope.() -> Unit)

Launches a new coroutine on the Dispatchers.IO context and executes the given block.

Link copied to clipboard
inline fun launchOnMain(crossinline block: suspend CoroutineScope.() -> Unit)

Launches a new coroutine on the Dispatchers.Main context and executes the given block.

Link copied to clipboard
inline fun <T> runOnDefault(crossinline block: suspend CoroutineScope.() -> T): T

This uses runBlocking([Dispatchers.Default]) for non suspend functions.

Link copied to clipboard
inline fun <T> runOnIO(crossinline block: suspend CoroutineScope.() -> T): T

This uses runBlocking([Dispatchers.IO]) for non suspend functions.

Link copied to clipboard
inline fun <T> runOnMain(crossinline block: suspend CoroutineScope.() -> T): T

This uses runBlocking([Dispatchers.Main]) for non suspend functions.

Link copied to clipboard
inline suspend fun <T> withDefaultContext(crossinline block: suspend CoroutineScope.() -> T): T

This uses withContext([Dispatchers.Default]) for suspend functions.

Link copied to clipboard
inline suspend fun <T> withIOContext(crossinline block: suspend CoroutineScope.() -> T): T

This uses withContext(Dispatchers.IO) for suspend functions.

Link copied to clipboard
inline suspend fun <T> withMainContext(crossinline block: suspend CoroutineScope.() -> T): T

This uses withContext([Dispatchers.Main]) for suspend functions.