All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.gateway.Ticker.kt Maven / Gradle / Ivy

package dev.kord.voice.gateway

import kotlinx.coroutines.*

/**
 * A reusable fixed rate ticker.
 */
internal class Ticker {
    // we only want one of these
    private var tickerJob: Job? = null

    suspend fun tickAt(intervalMillis: Long, block: suspend () -> Unit): Unit = coroutineScope {
        stop()
        tickerJob = launch {
            while (isActive) {
                block()
                delay(intervalMillis)
            }
        }
    }

    fun stop() {
        tickerJob?.cancel()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy