extractExecutionContext

extractExecutionContext

Signature

Description

Extracts the ExecutionContext from the RequestContext.

See withExecutionContext to see how to customise the execution context provided for an inner route.

See extract to learn more about how extractions work.

Example

def sample() =
  path("sample") {
    extractExecutionContext { implicit executor =>
      complete {
        Future(s"Run on ${executor.##}!") // uses the `executor` ExecutionContext
      }
    }
  }

val route =
  pathPrefix("special") {
    sample() // default execution context will be used
  }

// tests:
Get("/sample") ~> route ~> check {
  responseAs[String] shouldEqual s"Run on ${system.dispatcher.##}!"
}

Contents