All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.internal.NamedDispatcher.kt Maven / Gradle / Ivy

The newest version!
package kotlinx.coroutines.internal

import kotlinx.coroutines.*
import kotlinx.coroutines.DefaultDelay
import kotlin.coroutines.*

/**
 * Wrapping dispatcher that has a nice user-supplied `toString()` representation
 */
internal class NamedDispatcher(
    private val dispatcher: CoroutineDispatcher,
    private val name: String
) : CoroutineDispatcher(), Delay by (dispatcher as? Delay ?: DefaultDelay) {

    override fun isDispatchNeeded(context: CoroutineContext): Boolean = dispatcher.isDispatchNeeded(context)

    override fun dispatch(context: CoroutineContext, block: Runnable) = dispatcher.dispatch(context, block)

    @InternalCoroutinesApi
    override fun dispatchYield(context: CoroutineContext, block: Runnable) = dispatcher.dispatchYield(context, block)

    override fun toString(): String {
        return name
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy