Skip to content

Instantly share code, notes, and snippets.

View SrGaabriel's full-sized avatar
✴️
For he spoke, and it came to be.

Gabriel SrGaabriel

✴️
For he spoke, and it came to be.
  • Purdue University
View GitHub Profile
@SrGaabriel
SrGaabriel / SendChannelHeartbeat.kt
Created February 6, 2022 22:29
A simple alternative to Ktor's default heartbeat method
@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)