Created
January 8, 2020 16:51
-
-
Save emmano/5fbd6f7d47cff541768a33e147e55584 to your computer and use it in GitHub Desktop.
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
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