Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompletableFuture support for java client #2792

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

p-vorobyev
Copy link

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

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
Copy link
Contributor

levlam commented Feb 26, 2024

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.

Copy link

@timscharfenort8 timscharfenort8 left a comment

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants