I have an JavaFX-based application, written in Kotlin. JavaFX runs in a separate thread by default, and I want to ensure that the variable that is initialized in the main thread is ready when JavaFX reaches the part where it uses that variable.
Java has wait
and notify
methods that I'd use on that variable, but they aren't available in Kotlin.
I also looked into Kotlin coroutines, but they seem to be built around task dependency (i.e. one task can wait for another), but they don't work so simply with variables, and are using coroutines instead of threads, i.e. if I use coroutines to coordinate my variables, JavaFX still runs on a separate thread, which cannot be coordinated together with coroutines (or am I missing something?).
You can still use wait
and notifiy
in Kotlin, though not recommended.
You could also use CountDownLatch.