onSuccess的值不是scala.concurrent.Future [Any]

问题描述 投票:0回答:1

我想从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)

这是错误:

[错误]值onSuccess不是scala.concurrent.Future [Any]]的成员>

[[错误] f.onSuccess {

[错误] ^

[[错误]发现一个错误

[错误](编译/ compileIncremental)编译失败

也许我必须使用OnComplete之类的东西而不是OnSuccess有人可以帮忙!! ??

我想从某个网址发出请求,但无法通过val f:Future [Any] = actor1吗? SyncRequest(url)f.onSuccess {案例供稿:xml.Elem => ...

scala akka future actor
1个回答
0
投票

onSuccess方法在Scala 2.12中已弃用,在scala 2.13中已删除]

© www.soinside.com 2019 - 2024. All rights reserved.