Skip to content

Instantly share code, notes, and snippets.

@vegeta2102
Created March 24, 2021 13:12
Show Gist options
  • Save vegeta2102/7ff4fe4eefe3c969fd20ec9477df686c to your computer and use it in GitHub Desktop.
Save vegeta2102/7ff4fe4eefe3c969fd20ec9477df686c to your computer and use it in GitHub Desktop.
interface ProgressBarRepository {
val data: Flow<Int>
suspend fun startCountDown(count: Int)
}
class ProgressBarRepositoryImpl @Inject constructor() : ProgressBarRepository {
private val _data: MutableStateFlow<Int?> = MutableStateFlow(null)
override val data: Flow<Int>
get() = _data.filterNotNull()
override suspend fun startCountDown(count: Int) {
epeat(count) {
_data.emit(count - it)
// Delay 1 sec
delay(1000L)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment