https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Jason

01/22/2021, 7:16 AM
I call this function when app startup and stuck on loading screen . Here is the log console when debug:
Copy code
Log: Before delay
Log: Init Status: true
Log: Job Status: true
getUserInfo()
will not be called at all ??? What’s happen with flow ?
Copy code
interface InitRepository {
    val initFinish: Flow<Boolean>
}

suspend fun startApp() {

    checkStatus()
    waitInitializeDone()  -> App is stuck on waiting here... Forever waiting
    getUserInfo()
}


suspend fun waitInitializeDone() {
    withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
                val waitJob = launch {
                    Log.d("Before delay")
                    delay(10000L)
                    throw TimeoutException("Init process timeout")
                }
                initRepository.initFinish
                    .onEach { initFinish ->
                        Log.d("Init Status: $initFinish")
                        Log.d("Job Status: ${waitJob.isActive}")
                        if (initFinish && waitJob.isActive) {
                            waitJob.cancel()
                        }
                    }
                    .launchIn(this)
            }
}
y

Yigitunlu

01/25/2021, 3:44 PM
It's waiting init to be done
j

Jason

01/26/2021, 8:34 AM
No, even init is done. It still keep waiting status. I think should be make a
job
when waiting initFinish. If it to be done, cancel this job.
y

Yigitunlu

01/26/2021, 9:05 AM
Does initFinish flow ever finish?
4 Views