CommonFlow

class CommonFlow<T>(val origin: Flow<T>) : Flow<T>

A wrapper class for Kotlin Coroutine Flows for iOS. This is picked up from jetbrain's kotlinconf FlowUtils. So instead of flow, we only have callbacks that looks almost like a flow, It also exposes a Closeable. that is responsible for closing any scope we have on Kotlin side. so client can simple call close(). this creates a lifecycle flow we can deal with. it enables iOS and web to consume the flow data in a natural way. refer to the iOS and web samples for how to use. launchIn defines where we running our coroutine. here its running on Dispatchers.Main so this may cause issue with Threading controlled on Kotlin KMM. e.g in case the client want to run this flow in a Dispatchers background it will still run on Main. but will explorer this some other time.

If the Flow is wrapped in a Task and using CoroutineExceptionHandler we can grab the throws without crash but what if the Flow is not using a wrapper, it's causing a crashes. Here we added a way to catch any errors during the streaming of flows and send it as a callback to the client.

Note: Android should use collect instead of watch and handle errors by using try/catch or CoroutineExceptionHandler and on iOS adn web we are able to get a error value with readable Exception of what went wrong.

Constructors

Link copied to clipboard
constructor(origin: Flow<T>)

Types

Link copied to clipboard
class Job(val collectJob: Job)

Properties

Link copied to clipboard
private val origin: Flow<T>

Functions

Link copied to clipboard
fun <T> Flow<T>.asCommonFlow(): CommonFlow<T>
Link copied to clipboard
open suspend override fun collect(collector: FlowCollector<T>)
Link copied to clipboard
fun watch(stream: (T?, ClientException?) -> Unit): CommonFlow.Job

similar to calling collect{}. use watch to collect flow

Link copied to clipboard
fun <T> CommonFlow<T>.watch(stream: (T) -> Unit, error: (ClientException) -> Unit, scope: CoroutineScope = ContextScope.get(DispatchersProvider.Default)): CommonFlow.Job

Another way to consume common flows for JS ,