Skip to content

Instantly share code, notes, and snippets.

@pauloaapereira
Last active April 23, 2021 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauloaapereira/433519a261a261de97d29729d3745a6e to your computer and use it in GitHub Desktop.
Save pauloaapereira/433519a261a261de97d29729d3745a6e to your computer and use it in GitHub Desktop.
Jetpack Compose - Earthquake Effect_6
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