Easy to understand definition of “asynchronous eve

2019-01-02 14:46发布

I've encountered this term a lot, and even after Googling, still can't understand what exactly it means. Is there some easy-to-understand (ideally with examples) definition of what an asynchronous event is that someone can provide?

Thanks!

11条回答
ら面具成の殇う
2楼-- · 2019-01-02 15:28

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.

查看更多
唯独是你
3楼-- · 2019-01-02 15:28

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"

查看更多
公子世无双
4楼-- · 2019-01-02 15:28

Here's an example of an asynchronous operation in javascript (you need to have your javascript console open)

console.log('One!');
setTimeout(function(){console.log('Two!');},0);
//Doesn't wait
console.log('Three!');};

//OUTPUT:
//One!
//Three!
//Two!

The call to console.log('Two!') will be executed without blocking the rest of the code that happens after it.

In a real scenario, replace setTimeout with someone clicking a button on a webpage. The response to the button click will happen eventually, without blocking other code execution such as page rendering.

查看更多
还给你的自由
5楼-- · 2019-01-02 15:28

Synchronous Vs. Asynchronous Events

Some event handlers are called immediately when the event occurs. These are called ‘synchronous’ events. An example is DocumentNew. It gets called as soon as the user creates a new document.

However, some events are called shortly after the event occurs, usually after a short amount of idle time. These are called ‘asynchronous’ events. They are asynchronous because it would destabalize Source Insight if a user-written macro were to be called at the exact time the event occured.

查看更多
明月照影归
6楼-- · 2019-01-02 15:35

"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.

查看更多
登录 后发表回答