I have a simple sequence of IO operaion with 5 second pause.
implicit val timer = IO.timer(ExecutionContext.global)
def doSth(str: String): IO[Unit] = IO(println(str))
def greeting(): IO[Unit] =
doSth("Before timer.") *>
Timer[IO].sleep(5 second) *>
doSth("After timer")
val a = greeting().unsafeRunAsyncAndForget()
How to make timer without ExecutionContext.global
, IOApp
or to fix amount of threads in ExecutionContext.global
?
Try
implicit val timer = IO.timer(ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10)))