How do I fix compilation error with the spray example?

The spray documentation has an example onComplete directive

I copied the example:

path("divide" / IntNumber / IntNumber) { (a, b) =>
        onComplete(divide(a, b)) {
          case Success(value: Any) => complete(s"The result was $value")
          case Failure(ex)    => complete(StatusCodes.InternalServerError, s"An error occurred: ${ex.getMessage}")
        }
      }
def divide(a: Int, b: Int): Future[Int] = Future {
  a / b
}

      

And I got the error:

Type mismatch, expected: onCompleteFutureMagnet[NoninferedT], actual Future[Int]

      

It looks like something is very simply missing in the code.

Spray version - 1.3.1

Update

I downloaded spray sources and saw the same compilation errors in FutureDirectivesSpec.

+3


source to share


1 answer


import ExecutionContext.Implicits.global

      



works for me

+7


source







All Articles