Hi All, sorry if this is a super basic question, I...
# coroutines
c
Hi All, sorry if this is a super basic question, I’m starting to learn reactive programming and it is overwhelming! I am calling a library that returns a
Flux
, but I want to have instead a
Flow
. Is this something people do and if so, how do I go about doing it? Or am I thinking of this the wrong way? I have google searched, but surprisingly I can’t find any examples to learn from. Thanks so much!
z
c
Yes, it’s project reactor, sorry for not specifying. So many things with the same name, including Java Flow and Kotlin Flow! Thanks!
z
Yea, there are only about 5 terms and they’re used in 3 different ways by 10 different libraries 😅
😄 4
c
OMG yes! If you don’t mind me asking, what are the concerns that I should be wary of when converting from a Flux to a Flow?
Basically, I am calling a library that returns a Flux, and I want to change it to a Flow before sending it over a websocket (Rsocket) to my frontend
z
Unfortunately I can’t help you there, I have no experience with Reactor.
d
I couldn’t see a function to do this so I’m using
collect
instead, I’m just about to post a question about this very subject…
m
You can use the Publisher<T>.asFlow() extension method from the kotlinx-coroutines-reactive library: https://github.com/Kotlin/kotlinx.coroutines/blob/master/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt
Since Flux is a Publisher