The route concatenation extension operator “~” is implemented by
class RouteWithConcatenation(route: Route) {
/**
* Returns a Route that chains two Routes. If the first Route rejects the request the second route is given a
* chance to act upon the request.
*/
def ~(other: Route): Route = { ctx ⇒
import ctx.executionContext
route(ctx).fast.flatMap {
case x: RouteResult.Complete ⇒ FastFuture.successful(x)
case RouteResult.Rejected(outerRejections) ⇒
other(ctx).fast.map {
case x: RouteResult.Complete ⇒ x
case RouteResult.Rejected(innerRejections) ⇒ RouteResult.Rejected(outerRejections ++ innerRejections)
}
}
}
}
I think the class should extend AnyVal
and the argument of the ~
method could be by name. There is an old Spray issue where @sirthias says that route evaluation in akka-http will be lazy (cf. https://github.com/spray/spray/issues/780).