Answer the question
In order to leave comments, you need to log in
Is asynchrony a delay?
All tutorials talk about asynchrony in the context of deferred operations. Is it really just a delay? I thought it was parallel execution of different tasks in one thread. Kind of multitasking.
Answer the question
In order to leave comments, you need to log in
In general, yes. Imagine you have a code
var imageFromInternet = GetImageByUrl("http://example.com/big-image.bmp");
picture.image = imageFromInternet;
Why consider primarily in the context of pending operations?
The problem is that, by default, scripts are executed sequentially and synchronously. Thus, any operation that takes time will stop all program execution. And very often there are other tasks that, in general, can be performed independently. To do this, in many languages / environments, tools have been created for asynchronous execution of part of the operations. A special mechanism adds the ability to indicate that a certain operation is asynchronous and there is no need to wait for its completion, you can continue to execute the program further. At the same time, with the help of other operators, we can specify other operations that will be performed at the moment when the pending one is completed.
Let's say you make and display a program interface with a list of participants with various complex data. So, you can make a request for the data itself and the list asynchronous and immediately show and draw the entire interface (menus, buttons, table headers) to the user, and mark the table itself at that moment as "Loading", and then after receiving the data from the database, the function waiting for the response of our asynchronous request will already draw only the rest of the interface, the data itself. In this way, we will improve the user experience, because otherwise the user looks at a blank screen until we receive and prepare all the data to show everything at once.
Well, yes, often asynchrony also allows you to conveniently parallelize tasks, increasing the overall performance of the system as a whole.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question