【发布时间】:2021-07-14 05:03:16
【问题描述】:
我的这段代码抱怨 type mismatch; found: Unit required: scala.concurrent.Future ,而我返回的是 Future 。我是 Scala 的新手,不知道我在这里缺少什么。
val records: List[CommittableRecord[Either[Throwable, MyEvent]]] = ???
records.mapAsync(1){ x =>
val res = (x.value match {
case Right(event:MyEvent) =>
val future = getTask(event.get("task").getOrElse(""))
//future => Future[Try[Int]]
val k = future.map {
case Success(value) => value
case Failure(exception) => 0
}
//k => Future[Int]
})
}
【问题讨论】: