y

    yshrsmz

    2 years ago
    https://github.com/JetBrains/kotlinconf-app/blob/d56c3383d52dfdc32ba449d8daf9b9f633dd1d08/iosApp/iosApp/Controllers/HomeController.swift While looking at the KotlinConf app's code, I see iOS does not handle Closeables returned from CFlow. I wonder why.
    CFlow looks nice btw
    clhols

    clhols

    2 years ago
    I saw the same thing and also wondered that. Because CFlow starts "collecting" from the original flow on behalf of the UI, and passes back the "Job" in form of a Closable so that he UI can cancel the collecting coroutine when it doesn't want to get more values. But where do you clean up stuff in a UIViewController? viewDidUnload doesn't exist anymore...
    I am trying to use the same concept from CFlow in a ViewModel that implements CoroutineScope. A function to observe a dataFlow: Flow<Data> would then be:
    fun observeData(callback: (List<Data>) -> Unit) : Cancelable {
    val job = launch {
    dataFlow.collect { data ->
    callback(data)
    }
    }
    return object : Cancelable {
    override fun cancel() {
    job.cancel()
    }
    }
    }
    Cancelable is just an interface with fun cancel()