Common Flow
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.
Functions
similar to calling collect{}. use watch to collect flow
Another way to consume common flows for JS ,