Skip to content

Instantly share code, notes, and snippets.

@Felipe00
Last active November 29, 2017 19:42
Show Gist options
  • Save Felipe00/c7b4198408e7ccbb8a24dd8f83d80e7b to your computer and use it in GitHub Desktop.
Save Felipe00/c7b4198408e7ccbb8a24dd8f83d80e7b to your computer and use it in GitHub Desktop.
Como usar threads e fazer a página aguardar a requisição ser finalizada. [CompletableFuture<Result> , Firebase]
/** This method was called by Play! through the some tag in the html */
public CompletableFuture<Result> submit() {
auth = FirebaseAuth.getInstance(app);
final Form<LoginForm> filledForm = loginForm.bindFromRequest();
return signIn(filledForm);
}
private CompletableFuture<Result> signIn(Form<LoginForm> filledForm) {
final CompletableFuture<Result> resultFuture = new CompletableFuture();
final ApiFuture<UserRecord> firebaseFuture = auth.getUserByEmailAsync(filledForm.get().getEmail());
ApiFutures.addCallback(firebaseFuture, new ApiFutureCallback<UserRecord>() {
@Override
public void onFailure(Throwable throwable) {
Logger.debug("Erro: " + throwable.getMessage());
resultFuture.complete(badRequest(views.html.index.render()));
}
@Override
public void onSuccess(UserRecord userRecord) {
Logger.debug("Logado com sucesso");
resultFuture.complete(ok(views.html.profile.render(user)));
}
});
return resultFuture;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment