extractExecutionContext

extractExecutionContext

§シグネチャ

§説明

`` RequestContext``から `` ExecutionContext``を抽出します。

:ref:`-withExecutionContext`を参照して、内部ルートに提供される実行コンテキストをカスタマイズする方法を参照してください。

抽出がどのように機能するかについては、:ref:`-extract-`を参照してください。

§

  1. def sample() =
  2. path("sample") {
  3. extractExecutionContext { implicit executor =>
  4. complete {
  5. Future(s"Run on ${executor.##}!") // uses the `executor` ExecutionContext
  6. }
  7. }
  8. }
  9.  
  10. val route =
  11. pathPrefix("special") {
  12. sample() // default execution context will be used
  13. }
  14.  
  15. // tests:
  16. Get("/sample") ~> route ~> check {
  17. responseAs[String] shouldEqual s"Run on ${system.dispatcher.##}!"
  18. }