![]() ![]() Please see ThreadPools for more information on using custom execution contexts effectively. Trait MyExecutionContext extends ExecutionContextĬlass MyExecutionContextImpl (system: ActorSystem)Įxtends CustomExecutionContext(system, "my.executor")Ĭlass HomeController (myExecutionContext: MyExecutionContext, val controllerComponents: ControllerComponents) binding techniques listed on the "Scala Dependency Injection" documentation page Make sure to bind the new context class to this trait using one of the custom You can do this by creating a subclass of .CustomExecutionContext with a reference to the custom dispatcher. Using a Future is only half of the picture though! If you are calling out to a blocking API such as JDBC, then you still will need to have your ExecutionStage run with a different executor, to move it off Play’s rendering thread pool. The web client will be blocked while waiting for the response, but nothing will be blocked on the server, and server resources can be used to serve other clients. Play will then serve the result as soon as the promise is redeemed. By giving a Future instead of a normal Result, we are able to quickly generate the result without blocking. So what should we return as result if we are not yet able to generate it? The response is a future result!Ī Future will eventually be redeemed with a value of type Result. #Scala cannot resolve overloaded method map code#§Creating non-blocking actionsīecause of the way Play works, action code must be as fast as possible, i.e., non-blocking. Common examples of such blocking operations are JDBC calls, streaming API, HTTP requests and long computations.Īlthough it’s possible to increase the number of threads in the default execution context to allow more concurrent requests to be processed by blocking controllers, following the recommended approach of keeping the controllers asynchronous makes it easier to scale and to keep the system responsive under load. ![]() In other words, the application code should avoid blocking in controllers, i.e., having the controller code wait for an operation. The default configuration is tuned for asynchronous controllers. Play handles every request in an asynchronous, non-blocking way. Internally, Play Framework is asynchronous from the bottom up. §Handling asynchronous results §Make controllers asynchronous English ▾ English българин Français 日本語 Türkçe Asynchronous HTTP programming ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |