Open toplinuxsir opened 5 years ago
I know plenty of people are using coroutines with TornadoFX, though there is no special support for it. Not sure if it's even needed :) Take a look here for examples:
https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md#javafx
Better yet, ask in the Slack channel, I'm sure some of the guys can give you some example code!
@edvin Thanks a lot , I got it
do you success?The IDEA show me a error that Suspend function 'delay' should be called only from a coroutine or another suspend function
when I use the method named delay
in coroutines.
I use the library kotlinx-coroutines-javafx
,version is 1.3.5
Following is my code
class TestView() : View("My View") {
override val root = vbox {
button {
action {
GlobalScope.launch(Dispatchers.UI){
//idea show a error tip
delay(200L)
}
}
}
}
}
@Stars-One This code works for me, but why do you use Dispatchers.UI you need Dispatchers.JavaFx. what version of kotlin do you have?
also I would not recommend using GlobalScope. Work with coroutines can be hidden in the controller. You can also write auxiliary extension functions for calling coruntin
yes,I know the Dispatchers.UI
,It also show the same error tip.I just want to finish a simple example.
I use the kotlin verison 1.3.70,maybe the reason is the version of idea?my idea version is 2018.2 @SchweinchenFuntik
most likely yes, new versions of the kotlin compiler didn’t seem to work with the old IDEA
Try this. Use the JavaFX Dispatcher.
GlobalScope.launch(Dispatchers.IO) {
try {
val res = api.put<ApiSuccess<Entity>>("$api_url/entities") {
body = entity
}
launch(Dispatchers.JavaFx) {
fire(EntityUpdatedEvent(res.data))
}
} catch (e: ApiException) {
ErrorMessage("..err.", e.apiError.error).show()
}
}
Tornadofx can work with kotlin coroutine ? any examples? Thanks!