Asynchronous and Synchronous Terms

前端 未结 5 495
遇见更好的自我
遇见更好的自我 2020-12-08 00:49

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.

5条回答
  •  执笔经年
    2020-12-08 01:19

    Synchronous in the context of your question means that 2 parts are waiting for each other.
    For example if you have a client code that makes a request to a server and your code does not continue its processing until the response of the server arrives, then this means that your code is synchronous i.e. synchronous with the response of the server.
    If your client code makes the request but does not wait for a response and continues its processing and once the response of the request from the server arrives, then your code (in a specific handler for instance) starts to process the response then the handling is asynchronous i.e. the core client processing is asynhronous with the reponse of the server.
    These terms imply some short of dependency since it is not possible to convert a synchronous code to asynchronous if (using the example of client-server) the response is mandatory for the client to continue its 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."

    Wrong interpretation of the terms. It is not the program flow that synchronized. It is different parts that could be (e.g. threads) or could not be part of the same program that could be synchronized or not.

提交回复
热议问题