Agus Chapuis
Agus Chapuis

Reputation: 1

value onSuccess is not a member of scala.concurrent.Future[Any]

I want to make a request from a URL and am having a problem:

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)

This is the error:

[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

Maybe I have to use something like OnComplete and not OnSuccess?

Upvotes: 0

Views: 1273

Answers (1)

Ivan Stanislavciuc
Ivan Stanislavciuc

Reputation: 7275

onSuccess method is deprecated in Scala 2.12 and removed in scala 2.13

@deprecated("use foreach or onComplete instead (keep in mind that they take total rather than partial functions)", "2.12.0")

Your best friend is onComplete now

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

Upvotes: 5

Related Questions