arrow-fx / arrow.fx / Timer / sleep

sleep

abstract fun sleep(duration: Duration): Kind<F, Unit>

Sleeps for a given duration without blocking a thread.

import arrow.*
import arrow.fx.*
import arrow.fx.typeclasses.*
import arrow.fx.extensions.io.concurrent.concurrent

fun main(args: Array<String>) {
  //sampleStart
  fun <F> Concurrent<F>.delayHelloWorld(): Kind<F, Unit> =
    Timer(this).sleep(3.seconds).flatMap {
      effect { println("Hello World!") }
    }
  //sampleEnd
  IO.concurrent().delayHelloWorld()
    .fix().unsafeRunSync()
}

Do you like Arrow?

Arrow Org
<