Added Thread to retrieve information about the current thread
This commit is contained in:
parent
52d3b49baa
commit
98056a520a
|
@ -0,0 +1,15 @@
|
|||
package net.dankito.utils.multiplatform
|
||||
|
||||
|
||||
expect class Thread() {
|
||||
|
||||
companion object {
|
||||
|
||||
val current: Thread
|
||||
|
||||
}
|
||||
|
||||
|
||||
val threadName: String
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package net.dankito.utils.multiplatform
|
||||
|
||||
import platform.Foundation.NSOperationQueue
|
||||
import platform.Foundation.NSThread
|
||||
|
||||
|
||||
actual class Thread(private val thread: NSThread) {
|
||||
|
||||
actual companion object {
|
||||
|
||||
actual val current: Thread
|
||||
get() = Thread(NSThread.currentThread)
|
||||
|
||||
}
|
||||
|
||||
|
||||
actual constructor() : this(NSThread())
|
||||
|
||||
|
||||
actual val threadName: String
|
||||
get() {
|
||||
thread.name?.let { name ->
|
||||
if (name.isNotBlank()) {
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
return thread.description
|
||||
?: NSOperationQueue.currentQueue?.underlyingQueue?.description
|
||||
?: "Could not retrieve thread's name"
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.dankito.utils.multiplatform
|
||||
|
||||
|
||||
actual class Thread(private val thread: java.lang.Thread) : java.lang.Thread() {
|
||||
|
||||
actual companion object {
|
||||
|
||||
actual val current: Thread
|
||||
get() = Thread(currentThread())
|
||||
|
||||
}
|
||||
|
||||
|
||||
actual constructor() : this(java.lang.Thread())
|
||||
|
||||
|
||||
actual val threadName: String
|
||||
get() = thread.name
|
||||
|
||||
}
|
Loading…
Reference in New Issue