You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scala 3 下 Akka Streams 的 mapAsync 方法执行异常求助

Scala 3 环境下 Akka Streams mapAsync 方法挂起问题

我首次尝试使用 Scala 3 进行 Akka Streams 实验,尽管了解 Akka 对 Scala 3 仅提供实验性支持,但仍对以下简单程序无法正常运行感到诧异:

object HelloAkka extends App {

  implicit val actorSystem: ActorSystem = ActorSystem();
  implicit val executionContext: ExecutionContext = actorSystem.dispatcher

  val done = Source(1 to 5)
    .mapAsync(2)(n => Future {
      println(s"processing item $n in thread ${Thread.currentThread().getId}")
    })
    .runWith(Sink.ignore)

  Await.result(done, Duration.Inf)
  println("stream processing finished.")
  Await.result(actorSystem.terminate(), Duration.Inf)
  println("main thread terminated.")
}

使用 Scala 3.2.0 结合如下 build.sbt 构建时,程序在调用mapAsync时挂起(无 Future 执行):

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.2.0"  // 失败
// ThisBuild / scalaVersion := "2.13.8" // 正常

lazy val root = (project in file("."))
  .settings(
    name := "hello-akka",
    libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.6.20"
  )

切换至 Scala 2.13.8 时程序表现正常,Akka Streams 2.7.0-M1 版本也存在同样问题。由于mapAsync是 Akka Streams 编程的基础方法,我怀疑自己遗漏了某些明显错误。

内容的提问来源于stack exchange,提问作者Johann Heinzelreiter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 20:31:34