tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

CompletableFuture support for java client #2792

Open p-vorobyev opened 8 months ago

p-vorobyev commented 8 months ago

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.

client.send(new TdApi.GetMe()).thenAccept(userResult -> {
            if (userResult.error == null) {
                TdApi.User user = userResult.object;
                System.out.println("I'm " + user.firstName + " " + user.lastName);
            }
        });

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

levlam commented 8 months ago

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.