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

invirt.utils.thread-local.kt Maven / Gradle / Ivy

package invirt.utils

/**
 * Runs the specified [block] by first setting the specified [value] on this [ThreadLocal] and
 * then clearing it after the block has finished.
 */
fun  ThreadLocal.withValue(value: T, block: () -> R): R {
    this.set(value)
    val result = try {
        block()
    } finally {
        this.remove()
    }
    return result
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy