Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy to understand definition of "asynchronous event"? [closed]

People also ask

What is meant by an asynchronous event?

Events are asynchronous when they don't happen at the same time. If you pick up the crossword puzzle I started yesterday, we are working on it together but in an asynchronous fashion. Please do it in pencil. Asynchronous is the opposite of synchronous, which means happening at the same time.

What is synchronous and asynchronous events?

Synchronous simply means that all events are occurring in a certain time order that can be predicted. A certain event would always follow another and they can't be interchanged. Asynchronous is the opposite of synchronous. In asynchronous processes, there is no time order. Certain events can, and often do, interchange.

Why is asynchronous called asynchronous?

Thus asynchronous is "not at the same time". Whilst no function will return a result at the same time as being called, to the calling code it appears to do so, as the latter's execution stops whilst the function runs.

How asynchronous events are handled in JavaScript?

An async function can handle a promise called within it using the await operator. await can be used within an async function and will wait until a promise settles before executing the designated code. The await operators here ensure that the data is not logged before the request has populated it with data.


Non programming example:

Synchronous You want a pizza for dinner and you are out of the frozen kind. So you have to stop playing WOW which upsets your guild. You go to the kitchen, make the dough, cover it with sauce, add the cheese, and smother it your favorite bacon topping. You just spent 20 minutes of your time making the pizza with another 10 minutes in the oven. The timer beeps and you pull the hot pie out. You can sit back down in front of your computer, eat the pizza, and continue with your raid.

Asynchronous You want a pizza for dinner while playing WOW. You open up a browser window on your 5th monitor. You load up the Pizza website and order your extra cheesy bacon pizza with a side of bacon grease garlic sauce. You go back to your raid and after 20 minutes the door bell rings. You get the pizza. You sit back down in front of your computer, eat the pizza, and continue with your raid.

So what is the difference? One way you waste 20-30 minutes of precious WOW time, the other way you waste $20 plus tip.


Your page is delivered from the server to a client browser, somewhere out there in the Internet. The browser has drawn the page on a screen, and somebody — or some thing — is looking at it. It's a waiting game. Eyes shift back and forth, taking in this or that detail in quick jumps, darting to the side now and then, away from the screen, to investigate distractions in the environment. The clock ticks. The page glows softly, passively, as the user hovers inactive, hand loosely draped over a mouse, neck bent down and eyes more and more intent on something inviting that your page has to offer.

Suddenly, without any warning at all, the cursor begins to move as the hand on the mouse stiffens slightly and begins nudging the little plastic bump over the rough surface of the table. As the mouse moves, its surrogate on the screen moves in close imitation, grazing past interesting images and witty remarks in the content of your page. Eventually a decision is made, the movement pauses, a muscle or two contract slightly, and the mouse button is depressed by an insistent finger. The microswitch in the mouse triggers an electronic impulse, and suddenly the browser is made aware of what's happened: a mouse click.

In all that, everything about what the user has done while gazing at the page has happened in a way totally unpredictable to the browser, to any client code in your web page, to anything resident on your servers. There was no knowable "wait time" between human actions. The actions, therefore, as transmitted by the equipment hooked to the user's computer, happened when they happened and not according to a predictable clock — that is, they happened asynchronously.


Think of the end of an interview, and they guy says, "Don't call us, we'll call you". That is the essence of an asynchronous event.

Normally you define functions and you call functions explicitly. Your program has a structure where it starts from line 1, then line 2, and except for some conditional code and iterations, calling functions, etc., there is a simple, liner, synchronous structure.

But in some cases you have actions that are triggered by events outside of the direct control of the program, things that come from outside the program, like a user interface events (user clicks the mouse) or a network event (someone tries to connect to your server). Your code does not generate these events directly. They are generated outside of your program, often by the OS based on their monitoring of user interface devices and other systems. These are called asynchronous events.

Just remember, "Don't call us, we'll call you"


"In programming, asynchronous events are those occurring independently of the main program flow. Asynchronous actions are actions executed in a non-blocking scheme, allowing the main program flow to continue processing."

"With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page."

When you click Edit and Save on SO it is happening asynchronously.


An asynchronous event is an event that runs outside the application's main thread.

The best way to understand is to compare to events that run synchronously. The most typical example would be loading a web page.

When you went to this page, you clicked on a link and waited for the page to load and were not able to interact with or use this page until it finished loading. To contrast, if this page were to have an AJAX event (that's Asynchronous JavaScript and XML event) associated with some user action, this page would load some data from another source asynchronously - in parallel (theoretically) with any other actions going on.

Example with Two Synchronous Events (A and B): First A does something. When A is finished B does something.

Example with Two Asynchronous Events (A and B): Both A and B do something at the same time and neither event waits for the other.