I am needing explaining on how future is working in my play controller.
I have some code in my service layer which is calling a Java library API. When I first call my Java API like this in a controller:
def someController() = Action {
someJavaAPI()
Ok("done")
}
For this controller, I did not see any action. I expect action because of a call to someJavaAPI. Then somebody told me that someJavaAPI is dying because the controller is finishing too early. Is that right?
So I changed the code to be like this: I am wrapping someJavaAPI() method in a Future
def someJavaAPI() = Future {....code....}
Now I calling this like this in my contraoller:
def someController() = Action {
someJavaAPI().map{ _ => Ok("done") }
}
This is working very good.
My question is: is wrapping someJavaAPI in future makes controller thread wait until it finished and then does map function?
Also, what is Promise? Can I use Promise here? I am not sure.