Skip to content

Instantly share code, notes, and snippets.

@emmano
Created January 8, 2020 16: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 emmano/5fbd6f7d47cff541768a33e147e55584 to your computer and use it in GitHub Desktop.
Save emmano/5fbd6f7d47cff541768a33e147e55584 to your computer and use it in GitHub Desktop.
class TimerFlow {
@ExperimentalCoroutinesApi
suspend fun timer(
pollingDelay: Long,
coroutineDispatcher: CoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
) = flow {
while (true) {
delay(pollingDelay)
emit(Unit)
}
}.flowOn(coroutineDispatcher)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment