ContextValue

expect class ContextValue<E>

A common abstraction over ThreadLocal and CoroutineContext that integrates both worlds. Allows to set a value that can be read from everywhere on the current thread or coroutine. A suspendable function can call non suspendable functions and the value is synchronized between the CoroutineContext and the internal ThreadLocal.

actual class ContextValue<E>
actual class ContextValue<E>(initialStack: List<E>)

Constructors

Link copied to clipboard
expect constructor()
expect constructor(defaultValue: E)
actual constructor()
actual constructor(defaultValue: E)
constructor(initialStack: List<E>)
actual constructor()
actual constructor(defaultValue: E)

Types

Link copied to clipboard

Functions

Link copied to clipboard
expect fun <T> computeWith(newValue: E, body: () -> T): T
actual fun <T> computeWith(newValue: E, body: () -> T): T
actual fun <T> computeWith(newValue: E, body: () -> T): T
Link copied to clipboard
expect fun getAllValues(): List<E>
actual fun getAllValues(): List<E>
actual fun getAllValues(): List<E>
Link copied to clipboard
expect fun getValue(): E
actual fun getValue(): E
actual fun getValue(): E
Link copied to clipboard
expect fun getValueOrNull(): E?
actual fun getValueOrNull(): E?
actual fun getValueOrNull(): E?
Link copied to clipboard
fun <E, T> ContextValue<E>.offer(value: E, body: () -> T): T
Link copied to clipboard
expect suspend fun <T> runInCoroutine(newValue: E, body: suspend () -> T): T
actual suspend fun <T> runInCoroutine(newValue: E, body: suspend () -> T): T
actual suspend fun <T> runInCoroutine(newValue: E, body: suspend () -> T): T