Hi everyone How could I write the code below with ...
# coroutines
s
Hi everyone How could I write the code below with
Flow
Copy code
Observable.create(
            { emitter ->
                val process: Process = ProcessBuilder(commandAndArgs)
                    .redirectErrorStream(true)
                    .start()

                emitter.setCancellation {
                    process.destroy()
                }
        )
So idea is that I want when someone starts collecting the flow I will create a process and when a client stops collecting I will destroy the process
e
Copy code
channelFlow {
    val process = ...
    invokeOnClose { process.destroy() }
    process.inputStream.reader().useLines { lines ->
        for (line in lines) send(line)
    }
}
s
thank you