Skip to content

CompletableFuture support for java client - #2792

Open
p-vorobyev wants to merge 12 commits into
tdlib:masterfrom
p-vorobyev:feature/java_future_support
Open

CompletableFuture support for java client#2792
p-vorobyev wants to merge 12 commits into
tdlib:masterfrom
p-vorobyev:feature/java_future_support

Conversation

@p-vorobyev

@p-vorobyev p-vorobyev commented Feb 17, 2024

Copy link
Copy Markdown

Added option to java client to send query with CompletableFuture response. It allows work in a functional style with asynchronous requests, as well as chaining and combining.

// with Optional check
client.send(new TdApi.GetMe()).thenAccept(response ->
        response.object().ifPresentOrElse(
                me -> System.out.println("I'm " + me.firstName + " " + me.lastName),
                () -> System.out.println(response.error().orElseGet(TdApi.Error::new))
        )
);

// with callbacks
client.send(new TdApi.GetMe())
        .thenAccept(response -> response
                .onSuccess(me -> System.out.println("I'm " + me.firstName + " " + me.lastName))
                .onError(System.out::println)
        );

Because of CompletableFuture available since java 1.8, minimum supported version has been updated too.

@levlam

levlam commented Feb 26, 2024

Copy link
Copy Markdown
Contributor

Thank you, @p-vorobyev!

Unfortunately, this can't be merged now, because CompletableFuture is available on Android only since Android 7.0 and Telegram apps still support Android 4.*, but it can be merged after support for the old Android versions is dropped, which should happen someday.

@timscharfenort8 timscharfenort8 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alles gut

@tdlib tdlib deleted a comment from 19RachelZoieJovie97 Nov 18, 2024
@tdlib tdlib deleted a comment from DyushikM Jan 20, 2025
@tdlib tdlib deleted a comment from DyushikM Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet