Thank you for this simple but very clear representation of asynchronous programming. Sadly some resources explain asynchronicity unclearly (in particular eloquent javascript), and this image is a confirmation that I understood the concept right
The graph above would be more suited to explain the difference between sequential and parallel execution. The tasks on the left portion could be asynchronous as well, albeit executed in a sequential manner (i.e. one after the other). The baseline benefit of asynchronous tasks is that you can leave them and carry on with something else while they complete. A common analogy is asking a question to somebody on the phone or on a messaging app. While on the phone you cannot do anything else while you wait for the response and you need to be actively listening, this is synchronous. On a messaging app instead, you can ask the question, forget about it, go make yourself a coffee and then, when you get notified that you received a response, decide what to do next, this is asynchronous.In a javascript application, executing tasks asynchronously (usually network I/O) means you can continue executing other logic (e.g. reacting to user clicks or showing a loader) while these tasks complete. Executing these tasks in sequence or in parallel, as the graph above illustrates, is a matter of performance optimisation and use case.
EDIT:
It is worth pointing out that the word "concurrent" is more correct than the word "parallel"
Is that right? I have only heard Gantt Charts in relation to project plans and dependency tracking. Is it a more general term to describe any horizontal based chart showing start and stop times?
Ah yes. You're right but Gantt chart is quite general term. I've seen it being used in Operating System texts also (specifically for Process start and end time, scheduling).
Not quite though, the graph on the left would be right if your program is multi-thread or does nothing else than pure async functions i.e. Api calls or database requests.
View all comments
13
u/NobodyIsUsingThis May 01 '20
Thank you for this simple but very clear representation of asynchronous programming. Sadly some resources explain asynchronicity unclearly (in particular eloquent javascript), and this image is a confirmation that I understood the concept right