public static Result feedTitle( String feedUrl) {
return async(
WS.url(feedUrl).get().map(
new Function() {
public Result apply(WS.Response response) {
return ok("Feed title:" + response.asJson().findPath("title"));
}
}
)
);
}
This only applies if you are performing simple operations, such as passing the result of a WS call directly to the user. However, if you have to perform other operations on the result ,What should I do?
Look at the documentation, it looks like you can do this:
Promisepromise = WS.url("http://some. website.com").get();
Response response = promise.get(); // I've got the result, but I've also blocked
This is obviously not ideal Is there a way to make asynchronous calls while allowing Play to pass execution to other threads?
The most The good part is-this example does not feel too verbose. It is very well read and very simple to understand.
Play 2 allows you to perform async webservice calls via AsyncResult, It does not block the thread:
public static Result feedTitle(String feedUrl) {
return async(
WS.url(feedUrl). get().map(
new Function() {
public Result apply(WS.Response response) {
return ok("Feed title:" + response .asJson().findPath("title"));
}
}
)
);
}
This only applies to You are performing simple operations, such as passing the result of a WS call directly to the user. But, what if you have to perform other operations on the result?
Look at the documentation, it looks like you can do this:
Promisepromise = WS.url("http://some. website.com").get();
Response response = promise.get(); // I've got the result, but I've also blocked
This is obviously not ideal Is there a way to make asynchronous calls while allowing Play to pass execution to other threads?
Take a look at https://github.com/jroper/play-promise-presentation. This is how I design a project that may have multiple promise calls, etc. System, and operate various promise responses to the content required for more complex responses, etc. I really know it very well.
The best part is – this example doesn’t feel too verbose .It reads very well and is very simple to understand.