mapAsync 类型不匹配;发现:所需单位:scala.concurrent.Future
mapAsync type mismatch; found : Unit required: scala.concurrent.Future
我的这段代码抱怨 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]
})
}
变量赋值returnsUnit
,去掉val k =
或者把k
放在最后
我的这段代码抱怨 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]
})
}
变量赋值returnsUnit
,去掉val k =
或者把k
放在最后