Skip to content

Instantly share code, notes, and snippets.

@arnabkd
Created June 29, 2021 12:57
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 arnabkd/cc0fb87d44241638aace494f07c2ec26 to your computer and use it in GitHub Desktop.
Save arnabkd/cc0fb87d44241638aace494f07c2ec26 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import java.time.Duration
suspend fun <T: Any>tickerFlow(
period: Duration,
initialDelay: Duration = Duration.ZERO,
func: () -> T
) = flow<T> {
while (true) {
func()
delay(10_000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment