From 4999183324e8effab2f0f7b0fbfdee8e0f036374 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 11 Sep 2023 01:41:04 +0200 Subject: [PATCH] Improve example result handler --- .../main/java/it/tdlight/example/Example.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/example/src/main/java/it/tdlight/example/Example.java b/example/src/main/java/it/tdlight/example/Example.java index 04efa16..353bbb4 100644 --- a/example/src/main/java/it/tdlight/example/Example.java +++ b/example/src/main/java/it/tdlight/example/Example.java @@ -152,21 +152,18 @@ public final class Example { long chatId = update.message.chatId; // Get the chat title - client.send(new TdApi.GetChat(chatId)) - .thenApply(chatIdResult -> { - // Get the chat name - return chatIdResult.title; - }) - .whenComplete((chatTitle, error) -> { - if (error != null) { - // Print error - System.err.printf("Can't get chat title of chat %s%n", chatId); - error.printStackTrace(System.err); - } else { - // Print the message - System.out.printf("Received new message from chat %s (%s): %s%n", chatTitle, chatId, text); - } - }); + client.send(new TdApi.GetChat(chatId)).whenCompleteAsync((chatIdResult, error) -> { + if (error != null) { + // Print error + System.err.printf("Can't get chat title of chat %s%n", chatId); + error.printStackTrace(System.err); + } else { + // Get the chat name + String title = chatIdResult.title; + // Print the message + System.out.printf("Received new message from chat %s (%s): %s%n", title, chatId, text); + } + }); } /**