Skip to content

Instantly share code, notes, and snippets.

View SrGaabriel's full-sized avatar
🌐
And let me tell 'bout my life!

Gabriel SrGaabriel

🌐
And let me tell 'bout my life!
  • Purdue University
  • São Paulo
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)