Rename parameters of a thread function.

This commit is contained in:
Ilya Gorbunov
2015-11-18 05:08:19 +03:00
parent 47b3859641
commit 7035c300d0
@@ -16,32 +16,37 @@ public val currentThread: Thread
* Creates a thread that runs the specified [block] of code. * Creates a thread that runs the specified [block] of code.
* *
* @param start if `true`, the thread is immediately started. * @param start if `true`, the thread is immediately started.
* @param daemon if `true`, the thread is created as a daemon thread. The Java Virtual Machine exits when * @param isDaemon if `true`, the thread is created as a daemon thread. The Java Virtual Machine exits when
* the only threads running are all daemon threads. * the only threads running are all daemon threads.
* @param contextClassLoader the class loader to use for loading classes and resources in this thread. * @param contextClassLoader the class loader to use for loading classes and resources in this thread.
* @param name the name of the thread. * @param name the name of the thread.
* @param priority the priority of the thread. * @param priority the priority of the thread.
*/ */
public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread { public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread {
val thread = object : Thread() { val thread = object : Thread() {
public override fun run() { public override fun run() {
block() block()
} }
} }
if (daemon) if (isDaemon)
thread.setDaemon(true) thread.isDaemon = true
if (priority > 0) if (priority > 0)
thread.setPriority(priority) thread.priority = priority
if (name != null) if (name != null)
thread.setName(name) thread.name = name
if (contextClassLoader != null) if (contextClassLoader != null)
thread.setContextClassLoader(contextClassLoader) thread.contextClassLoader = contextClassLoader
if (start) if (start)
thread.start() thread.start()
return thread return thread
} }
/** @Deprecated("Use thread function with the 'isDaemon' parameter")
public fun thread(start: Boolean = true, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, daemon: Boolean, block: () -> Unit): Thread =
thread(start = start, isDaemon = daemon, contextClassLoader = contextClassLoader, name = name, priority = priority, block = block)
/**
* Gets the value in the current thread's copy of this * Gets the value in the current thread's copy of this
* thread-local variable or replaces the value with the result of calling * thread-local variable or replaces the value with the result of calling
* [default] function in case if that value was `null`. * [default] function in case if that value was `null`.
@@ -53,6 +58,5 @@ public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLo
* is stored for the current thread and then returned. * is stored for the current thread and then returned.
*/ */
public inline fun <T: Any> ThreadLocal<T>.getOrSet(default: () -> T): T { public inline fun <T: Any> ThreadLocal<T>.getOrSet(default: () -> T): T {
// TODO: replace let with apply or touch return get() ?: default().apply { set(this) }
return get() ?: default().let { set(it); it }
} }