异步和同步条款 [英] Asynchronous and Synchronous Terms

查看:138
本文介绍了异步和同步条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个词感到困惑的异步的有关编程的时候。这似乎意味着在编程术语相反作为它被定义为在字典中。例如,字 同步的意思是:


  

      
  1. 在同一时间发生的;在重合的时间;同期;
      同时的。


  2.   
  3. 正在进行以相同的速度和准确在一起;经常在一起。


  4.   

不过,维基百科说:


  

在编程中, 异步事件发生的那些
  独立于主程序流程。异步行动
  在一个非阻塞方案执行的操作,使主程序
  流入继续处理。


岂不东西是无阻塞的,允许的主要程序流程继续进行处理,同步或在同一时间发生的?好像这个词同步显示非阻塞和异步,堵。条款为什么会出现相关的编程时,反向使用,还是有事可做与较低级别的计算,我不明白?

当我使用同步AJAX调用,我做以下...

  $。阿贾克斯({
  网址:somefile.php,
  异步:假的,
  成功:{
    ......那得到成功运行code ...
  }
});......是可以获得Ajax的成功code运行后运行code ...

通过这一点,它实际上等待运行脚本的其余部分之前的响应,这是一个阻击战。那么为什么这被称为同步的,当它不与任何其他进程同步,但实际上相反?


解决方案

事实上,这是对这些情况下,当这个词的本义被颠覆,意味着什么比普遍使用的不同之一。

电信'同步'意味着接收机的信号时,它已准备好接收消息,并且只有这个信号之后,发射机将开始进行发射。当发射机与消息完成的,这将标志着它已经完成,从而使接收器现在可以处理接收到的消息,做任何它应该接下来做的事情。

这是一个过程简化和非常广阔的一个,但它应该给你的感觉从那里的意义(一)同步'进来JS。

在JS所以同步请求实际上是与该程序的主流程同步。程序发送请求到服务器(我已经准备好接受')并等待消息。从服务器消息都会有一个明确的结束('这里的消息结束 - 做你的工作')。当它被接收到,JS知道它可以与该程序的执行继续..

I'm confused by the term asynchronous when related to programming. It seems to mean the opposite in programming terms as what it is defined as in the dictionary. For example, the word synchronous means:

  1. occurring at the same time; coinciding in time; contemporaneous; simultaneous.

  2. going on at the same rate and exactly together; recurring together.

Yet, Wikipedia says:

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

Wouldn't something that is "non-blocking" and that allows "the main program flow to continue processing," be synchronized or "occurring at the same time"? It seems like the term synchronous suggests "non-blocking" and asynchronous, "blocking." Why do the terms appear to be used in reverse when related to programming, or does it have something to do with lower-level computing that I don't understand?

When I use an synchronous AJAX call, I do the following...

$.ajax({
  url: somefile.php,
  async: false,
  success: {
    ...code that gets run on success...
  }
});

...code that gets run after the ajax-success code runs...

With this, it actually waits for a response before running the rest of the script, it's a blocking action. Then why is this termed synchronous, when it's not synchronized with any other process, but actually the opposite?

解决方案

Indeed, it's one of these cases, where original meaning of the word was subverted and means something different than in popular usage.

'Synchronisation' in telecommunication means that receiver signals whenever it is ready to receive messages, and only after this signal the transmitter will start transmitting. When the transmitter is done with the message, it will signal it has finished, so that receiver can now process the received message and do whatever it is supposed to be doing next.

This is of course a simplification and a very broad one, but it should give you the feeling of from where the meaning of '(a)synchronous' comes in JS.

So synchronous request in JS is actually synchronised with the main flow of the program. The program sends request to server ('I'm ready to receive') and waits for message. Message from the server will have a well defined end ('the message ends here - do your job'). When it is received, JS knows it can continue with execution of the program..

这篇关于异步和同步条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆