Created
February 6, 2022 22:29
-
-
Save SrGaabriel/dc136b80119f340ee7a5dfdf542c98bd to your computer and use it in GitHub Desktop.
A simple alternative to Ktor's default heartbeat method
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
@OptIn(ObsoleteCoroutinesApi::class) | |
public suspend fun <T> SendChannel<T>.startHeartbeat( | |
scope: CoroutineScope, | |
intervalMillis: Long, | |
delayMillis: Long, | |
content: T | |
): Job = scope.launch { | |
val channel = ticker(intervalMillis, delayMillis) | |
channel.consumeEach { | |
[email protected](content) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment