@Singleton
public class HttpExecutionContext
extends java.lang.Object
This is essentially a factory for getting an executor for the current HTTP context. Tasks executed by that executor will have the HTTP context setup in them.
For example, it may be used in combination with CompletionStage.thenApplyAsync
,
to ensure the callbacks executed when the completion stage is redeemed have the correct context:
CompletionStage<WSResponse> response = ws.url(...).get(); CompletionStage<Result> result = response.thenApplyAsync(response -> { return ok("Got response body " + ws.body() + " while executing request " + request().uri()); }, httpExecutionContext.current());Note, this is not a Scala execution context, and is not intended to be used where Scala execution contexts are required.
Constructor and Description |
---|
HttpExecutionContext(java.util.concurrent.Executor delegate) |
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.Executor |
current()
Get the current executor associated with the current HTTP context.
|
@Inject public HttpExecutionContext(java.util.concurrent.Executor delegate)
public java.util.concurrent.Executor current()
Note that the returned executor is only valid for the current context. It should be used in a transient fashion, long lived references to it should not be kept.