msink / kotlin-libui

Kotlin/Native interop to libui: a portable GUI library
MIT License
652 stars 50 forks source link

Coroutines #16

Open msink opened 6 years ago

msink commented 6 years ago

Need to integrate coroutines support from https://github.com/Kotlin/kotlinx.coroutines/tree/master/native and add sample similar to timer but based on coroutines.

abbas-oveissi commented 5 years ago

Is it possible to use Coroutines with Kotlin-libui in Linux application? My code doesn't work.

fun main() = runBlocking {
    appWindow(
            title = "Coroutine",
            width = 500,
            height = 500
    ) {
        vbox {
            button("Launch Coroutine") {
                action {
                    async(Dispatchers.Main) {
                        printSomething()
                    }
                }
            }
        }
    }
}

suspend fun printSomething() {
    println("Run");
}
Dominaezzz commented 5 years ago

How does it not work?

abbas-oveissi commented 5 years ago

When I click on the Button, nothing happens. After closing the Box, "Run" is printed.

Dominaezzz commented 5 years ago

Dispatchers.Main hasn't been implemented yet for kotlin-libui.

abbas-oveissi commented 5 years ago

Is it difficult to implement it myself? do you have any resources or sample code?

Dominaezzz commented 5 years ago

You can implement you own Dispatcher. This might help.