Skip to content

Instantly share code, notes, and snippets.

@ekoo
Last active May 22, 2020 06:07
Show Gist options
  • Save ekoo/226a82ab32d200b1f684b7792c8e3f7a to your computer and use it in GitHub Desktop.
Save ekoo/226a82ab32d200b1f684b7792c8e3f7a to your computer and use it in GitHub Desktop.
.................
val timeLeft: LiveData<Int> get() = _timeLeft
private val _timeLeft = MutableLiveData(60)
private val countDownTimer = flow {
for (timeLeftOnTimer in 60 downTo 0){
emit(timeLeftOnTimer)
delay(1000)
}
}
fun startCountDownTimer(){
score = 1
_liveScore.value = score
isGameStarted = true
viewModelScope.launch {
try {
countDownTimer.collect{ timeLeft ->
_timeLeft.value = timeLeft
}
} finally {
channel.send(score)
resetGame()
}
}
}
.................
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment