Note: I am new to creating the framework.
For my game! project, I need some form of asynchronous programming. I just need to display the view, doing the processing in the background, and then redirect or a new rendered form.
This question was asked unanswered. I looked at the Play Documentation pages, I did not find any solution there.
What I tried:
I tried to change the AsynchController that is specified using the play starter example . However, when navigating to http://localhost/message function seems to act more like hibernation than a scheduled task that has been set and "forgotten", i.e. You can continue with further coding.
Fragment AsynchController: with its own modification
public CompletionStage<Result> message() { return getFutureMessage(5, TimeUnit.SECONDS).thenApplyAsync(s -> ok(views.html.User.Account.verified.render()), exec); } private CompletionStage<String> getFutureMessage(long time, TimeUnit timeUnit) { CompletableFuture<String> future = new CompletableFuture<>(); actorSystem.scheduler().scheduleOnce( Duration.create(time, timeUnit), () -> future.complete("Waiting 5 seconds..."), exec ); return future; }
route entry
GET /message controllers.AsyncController.message
Goal:
My goal was for the Waiting 5 seconds... message to be displayed, followed by a delay of +/- 5 seconds. After that, it will reach the βfutureβ (is that right?), As a result of which it will display the view (or redirect to the controller), in this case the verified page ( verified for the account).
I'm on the right track with my original goal, where can I get a good example of something like this?