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

io.vertx.kotlin.coroutines.SetPeriodic.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
package io.vertx.kotlin.coroutines

import io.vertx.core.Vertx
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/**
 * Set a periodic timer to fire every {@code delay} milliseconds, at which point a suspending function will be invoked
 *
 * @param delay  the delay in milliseconds, after which the timer will fire
 * @param handler  the handler that will be called with the timer ID when the timer fires
 * @return the unique ID of the timer
 */
fun Vertx.setPeriodicAwait(delay: Long, handler: suspend (Long) -> Unit): Long {
  val coroutineScope = CoroutineScope(this.dispatcher())
  return this.setPeriodic(delay) { timerId ->
    coroutineScope.launch {
      handler(timerId)
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy