3
votes

Spray documentation has example about onComplete directive

I copied 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 error:

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

It is seems that something very simple missed in code.

Spray version is 1.3.1

Updated

I have downloaded spray sources and see same compilation errors in FutureDirectivesSpec.

1
You need to make sure an implicit ExecutionContext is in scope. If you are seeing the same problem compiling spray itself, can you post the exact steps you took for compiling spray? - jrudolph
Can you show us your imports? Perhaps you are missing some implicit. - Lukas Eichler

1 Answers

7
votes
import ExecutionContext.Implicits.global

works for me