Aditya Wasan
02/01/2021, 6:05 AMprivate val _isCacheReady = MutableStateFlow(false)
val isCacheReady = _isCacheReady.asStateFlow()
After filling up the cache, I'm updating the value
_isCacheReady.value = true
And here's the observing code
init {
lobstersRepository.isCacheReady.onEach {
_savedPosts.value = lobstersRepository.getAllPostsFromCache()
}.launchIn(viewModelScope)
}Dominaezzz
02/01/2021, 6:58 AMonEach , do they get printed?Aditya Wasan
02/01/2021, 7:02 AMonEach is called the first time when ViewModel initialises. However, onEach is not called again when I set _isCacheReady.value = true.Dominaezzz
02/01/2021, 7:19 AM_isCacheReady.value set to true already?Aditya Wasan
02/01/2021, 7:52 AM_isCacheReady.value after updating it.Dominaezzz
02/01/2021, 8:09 AMonEach is called, is it true? (That's what I meant)Aditya Wasan
02/01/2021, 10:33 AMDominaezzz
02/01/2021, 10:37 AMZach Klippenstein (he/him) [MOD]
02/01/2021, 4:53 PM.onCompletion { println("complete: $it") } before your launchInAditya Wasan
02/03/2021, 6:47 AMAditya Wasan
02/03/2021, 7:04 AMonCompletion {} is called after the app is closed.Aditya Wasan
02/03/2021, 7:06 AM