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.
import ExecutionContext.Implicits.global
works for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With