I'm experienced in Rx but just embarking on my fir...
# tornadofx
d
I'm experienced in Rx but just embarking on my first 'Reactive Coroutines' journey with JavaFX - is this a reasonable way to get a
Channel<ActionEvent>
from a
Button
? Is there an established library that already implements these kinds of Coroutines wrappings for JavaFX?
d
Copy code
@ExperimentalCoroutinesApi
fun Button.actionEvents(scope: CoroutineScope) : Channel<ActionEvent> {
    val actionEvents = Channel<ActionEvent>(Channel.UNLIMITED)
    this@actionEvents.onAction = EventHandler { actionEvent ->
        actionEvents.offer(actionEvent)
    }
    actionEvents.invokeOnClose {
        this@actionEvents.onAction = null
    }
    return actionEvents
}
launch
is a bit heavy for this.
👍 1
d
Thanks @Dominaezzz. Wondered about that but I'd missed
offer
, good to know 👍