Anyone know of a library that implements Coroutine...
# tornadofx
d
Anyone know of a library that implements Coroutine Channel/Flow wrappings for JavaFX component events? Or is there space to grow a new one?
d
Not exactly an answer but I thought you might like to see it. https://kotlinlang.slack.com/archives/C1CFAFJSK/p1565187506478200
(I'm looking for something similar too)
d
👍
I've wrapped JavaFX Property at least, thanks to your help, next I need to define a Channel/Flow that immediately emits the current value of a Property, followed by any changes.
Which is a hybrid cold/hot behaviour but something common in Rx.
Useful when your code subscribes to a control part way through its lifecycle - which is again quite common once you are developing complex UI's with Rx, or wanting to emit default values that are defined in FXML i.e. set before the lifecycle.
d
ConflatedBroadcastChannel
.
d
I'll check it out... effectively I want to concatenate a cold flow of size 1, with a channel of subsequent updates
d
Yup, that's pretty much it.
d
...just read. Delightful - thanks!!
BTW I will share a lib once I get something test and worth sharing.
Plenty of dog-fooding to go through first 😄
Appeared too easy 😂
Copy code
@ExperimentalCoroutinesApi
fun <T> Property<T>.values() : BroadcastChannel<T> {
    val values = ConflatedBroadcastChannel<T>(value)
    val listener = ChangeListener<T> { _,_,newValue ->
        values.offer(newValue)
    }
    addListener(listener)
    values.invokeOnClose { removeListener(listener) }
    return values
}
r
You might want to make specialized functions for the primitive number properties, as they are all
Property<Number>
.
👌 1