In Play Framework 2.2.2, I\'d like to return a Promise. However I\'m calling a function which needs access to the variables stored in Http.Context.current()
(th
Yes, HttpExecutionContext
is what you need.
When an HttpExecutionContext
is created it gets the current thread's Http.Context and stores it. Then, when the HttpExecutionContext
is later used to execute code it restores the Http.Context.
All Promise methods use an HttpExecutionContext wrapped around the default ExecutionContext so they should propagate the Http.Context
correctly across threads.
Your example code above should work fine, for example. However you do need to make sure that when you call getAvailableServices
, that the Http.Context
is available in the thread you're calling from. If the Http.Context
isn't available when you call the method, then the HttpExecutionContext
will be unable to capture the Http.Context
from that thread and propagate it when the promise's Function0
is applied.