S
S
Sashulya2020-06-25 14:16:06
Android
Sashulya, 2020-06-25 14:16:06

How to wait for an asynchronous method to execute?

Hey!
The situation is as follows - I have a certain API on Kotlin, which has a method that I really need. This method, as I understand it, has a handler and I get its result asynchronously and can only execute the code in the received onSuccess callback. But I need to get the results of this method synchronously.
How can this be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Developer, 2020-06-25
@samodum

Change the model to synchronous, obviously.

A
alekseyHunter, 2020-07-22
@alekseyHunter

I get its result asynchronously and can only execute the code in the received onSuccess callback.

If you make the method synchronous, the application may "hang", because it is not known how long the request will be processed.
Better rewrite under asynchronous.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question