简体   繁体   中英

Why not synchronously instead of asynchronously?

I am reading articles about the difference between synchronous and asynchronous behavior and ... I know I am stumbling upon words but I don't understand why the two terms are not used the other way around.

Synchronous means "occurring at the same time; coinciding in time; contemporaneous; simultaneous." while asynchronous means "1.not occurring at the same time.2. (of a computer or other electrical machine) having each operation started only after the preceding operation is completed." (dictionary.com)

However when it comes to programming the terms seem to be used differently.

The terms aren't used differently, you just have to understand how to interpret them.

Using Ajax as an example, because it is a common use case:

The operation is: "Make an HTTP request, then do something with the response".

If it is synchronous, then that all happens in one long chunk (the bottom part of the diagram below).

If it is asynchronous, then the HTTP request is sent and then the JavaScript engine does something else while it waits for the HTTP response to come back over the network. Once the JS engine is no longer busy and the response has arrived, it does the rest of the Ajax operation.

The synchronous approach is "occurring at the same time" because it isn't split up with other stuff happening in the meantime.

The second definition you quoted fits with no stretching at all.

图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM