stream
fun <Event, Response> stream(coroutineScope: CoroutineScope, scope: suspend StreamBuilderScope<Event, Response>.() -> Unit): ReceiveStream<Event, Response>
Creates a new ReceiveStream and runs the given scope in a new coroutine. The scope can use the StreamBuilderScope.send method to send events to the sender of the stream.
The returned ReceiveStream will be active until the scope finishes or the stream is closed. After that, the stream will reject any new events.
Docs: https://gp.acrobits.cz/master/documentation/core/android/writing-modern-android/streams
Example usage:
val merged = stream(coroutineScope) {
// This is the coroutine scope you passed in with added `send` functions
// Send directly
send(event1)
// Or launch new coroutines
launch {
for (event in someExternalEvents)
send(event) // same send as on SendStream
}
// You can obviously have multiple launches
launch {
...
}
}Content copied to clipboard