Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala/Akka Future onComplete Success compiler error

I have an actor that waits for the results of a future. Calling onComplete of the future causes a compiler error:

error: constructor cannot be instantiated to expected type [scalac] found : akka.actor.Status.Success [scalac] required: scala.util.Try[Iterable[Any]] [scalac] case Success(result: List[PCBInstanceStats]) => { [scalac] ^

Actor's receive:

case "pcbStatus" => {
      val future = Future.traverse(context.children)(x => {
        (x ? "reportStatus")(5 seconds)
      })

      future.onComplete {
        case Success(result: List[PCBInstanceStats]) => {
          self ! result
        }
      }

Not sure how to provide the right type of parameter for this.

like image 328
binarygiant Avatar asked Apr 09 '14 15:04

binarygiant


1 Answers

[scalac] found : akka.actor.Status.Success 

That means the compiler sees your Success and thinks it's an akka.actor.Status.Success, when really you mean a scala.util.Success. You probably have an import somewhere that is importing the akka Success class.

Either remove the import for akka.actor.Status.Success, or resolve the ambiguity by either fully-qualifying the class, or using an import alias, e.g.

import scala.util.{Success => ScalaSuccess}

future.onComplete {
  case ScalaSuccess(result) => ...
  // or
  case scala.util.Success(result) => ...
}
like image 141
Dylan Avatar answered Nov 09 '22 05:11

Dylan