Last active
May 22, 2020 06:07
-
-
Save ekoo/226a82ab32d200b1f684b7792c8e3f7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
................. | |
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