Thread.kt
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
namespace std.concurrent
|
||||
|
||||
import java.lang.*
|
||||
|
||||
inline var Thread.name : String
|
||||
get() = getName().sure()
|
||||
set(name: String) { setName(name) }
|
||||
|
||||
inline var Thread.daemon : Boolean
|
||||
get() = isDaemon()
|
||||
set(on: Boolean) { setDaemon(on) }
|
||||
|
||||
inline val Thread.alive : Boolean
|
||||
get() = isAlive()
|
||||
|
||||
inline var Thread.priority : Int
|
||||
get() = getPriority()
|
||||
set(prio: Int) { setPriority(prio) }
|
||||
|
||||
inline var Thread.contextClassLoader : ClassLoader?
|
||||
get() = getContextClassLoader()
|
||||
set(loader: ClassLoader?) { setContextClassLoader(loader) }
|
||||
|
||||
fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: fun():Unit) : Thread {
|
||||
val thread = object: Thread() {
|
||||
override fun run() {
|
||||
block()
|
||||
}
|
||||
}
|
||||
if(daemon)
|
||||
thread.setDaemon(true)
|
||||
if(priority > 0)
|
||||
thread.setPriority(priority)
|
||||
if(name != null)
|
||||
thread.setName(name)
|
||||
if(contextClassLoader != null)
|
||||
thread.setContextClassLoader(contextClassLoader)
|
||||
if(start)
|
||||
thread.start()
|
||||
return thread
|
||||
}
|
||||
Reference in New Issue
Block a user