-
Notifications
You must be signed in to change notification settings - Fork 44
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
How to send requests synchronously? #12
Comments
You can wrap the send request into a CompletableFuture. public static <T extends TdApi.Object> T sendSynchronously(TelegramClient client, TdApi.Function request, int timeoutSeconds)
throws ExecutionException, InterruptedException {
var response = new CompletableFuture<>();
client.send(request, response::complete, response::completeExceptionally);
return (T) response.completeOnTimeout(new TdApi.Error(408, "Request Timeout"), timeoutSeconds, TimeUnit.SECONDS).get();
} Example: TdApi.User me = sendSynchronously(tc, new TdApi.GetMe(), 10); |
the work of this function gives me a Request Timeout, but I'm doing everything right. what could be the problem ? |
@lexanderav, it may take some time for Telegram functions to return a result, so you have two options:
|
Thanks for your reply. I increase the value of timeoutSeconds but no response comes. |
Hi!
Is there any chance to send requests to Telegram API synchronously? In my application I need some things to do one by one.
The text was updated successfully, but these errors were encountered: