Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How fix compilation error on spray example?

Tags:

types

scala

spray

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.

like image 610
Cherry Avatar asked Jun 08 '26 13:06

Cherry


1 Answers

import ExecutionContext.Implicits.global

works for me

like image 113
0oAimZo0 Avatar answered Jun 10 '26 03:06

0oAimZo0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!