如何在没有ExecutionContext.global和IOApp的情况下使用cat效果?

问题描述 投票:1回答:1

我有一个简单的IO操作序列,暂停5秒。

  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()

如何在没有ExecutionContext.globalIOApp的情况下制作计时器或修复ExecutionContext.global中的线程数量?

scala spring-data-jpa scala-cats
1个回答
2
投票

尝试

implicit val timer = IO.timer(ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10)))

How to configure a fine tuned thread pool for futures?

© www.soinside.com 2019 - 2024. All rights reserved.