简体   繁体   English

为什么不同步而不是异步?

[英]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." 异步是指“ 1.不能同时发生2.计算机(或其他电机的)同时发生,只有在完成前一个操作后才开始每个操作”。 (dictionary.com) (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: 以Ajax为例,因为这是一个常见的用例:

The operation is: "Make an HTTP request, then do something with the response". 操作是:“发出HTTP请求,然后对响应进行处理”。

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. 如果是异步的,那么HTTP请求发送,然后JavaScript引擎做别的东西在等待HTTP响应回来在网络上。 Once the JS engine is no longer busy and the response has arrived, it does the rest of the Ajax operation. 一旦JS引擎不再忙碌并且响应已经到达,它将执行其余的Ajax操作。

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. 您引用的第二个定义完全没有延伸。

图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制Windows Service同步运行而不是异步运行? - How do I force a Windows Service to run synchronously instead of asynchronously? 承诺是异步解决还是同步解决? - Do promises resolve asynchronously or synchronously? node js:为什么我不能在 jason.js 中异步写入然后同步读取? - node js : why can't I write asynchronously in jason.js and then read it synchronously? 异步下载与同步下载多个文件 - Downloading Multiple Files Asynchronously vs. Synchronously 代码工作,但似乎同步运行而不是异步 - Code works but seems to run synchronously not asynchronously boost :: signals插槽是同步还是异步调用? - Are boost::signals slots called synchronously or asynchronously? Dart/Flutter 测试是同步执行还是异步执行 - Are Dart/Flutter tests executed synchronously or asynchronously 知道function里面是同步调用还是异步调用 - Know within function if it was called synchronously or asynchronously 异步触发的事件可以在窗体上同步运行吗? - Can an asynchronously fired event run synchronously on a form? 如何返回 CompletionStage<response> Quarkus 中的同步和异步?</response> - How to return CompletionStage<Response> both synchronously and asynchronously in Quarkus?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM