https://kotlinlang.org logo
#flow
Title
# flow
c

Christian S.

01/26/2021, 2:38 PM
Hello! I try to start/launch a Kotlin Flow from Groovy/Spock. The Flow I want to test is created by a Kotlin function. This is what I roughly try to achieve:
Copy code
def results = []
BuildersKt.runBlocking(EmptyCoroutineContext.INSTANCE) {
    sut.createFlow(someArg).collect { results << it }
}
I have found this SO post but haven't discovered a simpler solution, yet. Can someone please help me out? Thanks!
Hello @elizarov, is there a way to start Kotlin Flows from non-Kotlin code (e.g. using Java/Groovy) and if so, how?
e

elizarov

03/01/2021, 7:46 AM
Yes, you can convert a flow to some Java-friendly reactive type that does not rely on coroutines. We do provide a bunch of converts (to Rx, to project Reactor, and to Java 9 flows).
3 Views