I want to know how we can send the message from one thread to the main thread in kotlin. ps: Not on android. I don't want any android platform specific answer.
I've tried this in android platform as below
private val uiThreadHandler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
(msg.obj as () -> Unit)()
}
}
And using this as
uiThreadHandler.obtainMessage(0, block).sendToTarget()
I want to achieve this on plain kotlin. How to achieve this thread communication in kotlin ?