Hi
I wanted to understand the how to do non-blocking I/O.
I have login API:
public static Promise<Result> login() {
Logger.debug("Application.login()-------------- >");
Promise<String> promiseOfJson = Promise.promise(
new Function0<String>() {
@Override
public String apply() throws Throwable {
return loginService();
}
}
);
return after(promiseOfJson);
}
loginService() {
// Now this function calls other server to authenticate the credentials.. username and password,
// the function call loginAuthenticateServer
Promise<JsonNode> promise = loginAuthenticateServer();
// now I need to wait here until I get the data
My Questions are:
DO I need to call wait() or get() on the promise
Is it correct way of doing Async IO
}
public static Promise<JsonNode> loginAuthenticateServer(String serverUrl, JsonNode requestBodyJson) {
Promise<WSResponse> response = WS.url(serverUrl)
.setContentType(RequestConstants.REQUEST_CONTENT_TYPE_JSON)
.post(requestBodyJson);
return response.map(new Function<WSResponse, JsonNode>() {
@Override
public JsonNode apply(WSResponse wsResponse) throws Throwable {
return wsResponse.asJson();
}
});
}