Last active
April 23, 2021 22:51
-
-
Save pauloaapereira/433519a261a261de97d29729d3745a6e to your computer and use it in GitHub Desktop.
Jetpack Compose - Earthquake Effect_6
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
fun CoroutineScope.flowTimer( | |
duration: Long, | |
period: Long, | |
onFinished: () -> Unit = {}, | |
onTick: (Long) -> Unit | |
) = | |
this.launch { | |
(duration downTo 0 step period).asFlow() | |
.onEach { | |
onTick(it) | |
delay(period) | |
} | |
.onCompletion { | |
onFinished() | |
} | |
.collect() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment