akka onSuccess的值不是scala.concurrent.Future的成员[任何]

wgxvkvu9  于 2022-11-06  发布在  Scala
关注(0)|答案(1)|浏览(118)

我想从URL发出请求,但遇到了问题:

val f: Future[Any] = actor1 ? SyncRequest(url)
  f.onSuccess {
    case feed: xml.Elem => 
      val feedInfo = FeedInfo(
              ((feed \ "channel") \ "title").headOption.map(_.text).get,
              ((feed \ "channel") \ "description").headOption.map(_.text),
              ((feed \ "channel") \\ "item").map(item =>
                FeedItem((item \ "title").headOption.map(_.text).get,
                          (item \ "link").headOption.map(_.text))
              ).toList
            )

      complete(feedInfo)

这是错误:

[error] value onSuccess is not a member of scala.concurrent.Future[Any]
[error]                 f.onSuccess {
[error]                     ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

也许我必须使用类似OnComplete的东西,而不是OnSuccess

vohkndzv

vohkndzv1#

onSuccess方法在Scala 2.12中已弃用,在Scala 2.13中已删除
@deprecated(“请改用foreachonComplete(请记住,它们接受全部函数而不是部分函数)",“2.12.0”)
你最好的朋友现在是onComplete

f.onComplete {
  case Success(value) => ???
  case Error(ex) => ???
}

相关问题