【问题标题】:mapAsync type mismatch; found : Unit required: scala.concurrent.FuturemapAsync 类型不匹配;发现:所需单位:scala.concurrent.Future
【发布时间】: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]
        })
      }

【问题讨论】:

    标签: scala akka


    【解决方案1】:

    变量赋值返回Unit,只需去掉val k = 或者把k放在最后

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      相关资源
      最近更新 更多