Rename parameters of a thread function.
This commit is contained in:
@@ -16,32 +16,37 @@ public val currentThread: Thread
|
||||
* Creates a thread that runs the specified [block] of code.
|
||||
*
|
||||
* @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.
|
||||
* @param contextClassLoader the class loader to use for loading classes and resources in this thread.
|
||||
* @param name the name 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() {
|
||||
public override fun run() {
|
||||
block()
|
||||
}
|
||||
}
|
||||
if (daemon)
|
||||
thread.setDaemon(true)
|
||||
if (isDaemon)
|
||||
thread.isDaemon = true
|
||||
if (priority > 0)
|
||||
thread.setPriority(priority)
|
||||
thread.priority = priority
|
||||
if (name != null)
|
||||
thread.setName(name)
|
||||
thread.name = name
|
||||
if (contextClassLoader != null)
|
||||
thread.setContextClassLoader(contextClassLoader)
|
||||
thread.contextClassLoader = contextClassLoader
|
||||
if (start)
|
||||
thread.start()
|
||||
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
|
||||
* thread-local variable or replaces the value with the result of calling
|
||||
* [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.
|
||||
*/
|
||||
public inline fun <T: Any> ThreadLocal<T>.getOrSet(default: () -> T): T {
|
||||
// TODO: replace let with apply or touch
|
||||
return get() ?: default().let { set(it); it }
|
||||
return get() ?: default().apply { set(this) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user