I know that callback function runs asynchronously, but why?

前端 未结 3 1379
广开言路
广开言路 2020-11-22 13:39

Which part of syntax provides the information that this function should run in other thread and be non-blocking?

Let\'s consider simple asynchronous I/O in node.js

3条回答
  •  忘了有多久
    2020-11-22 13:48

    A callback is not necessarily asynchronous. Execution depends entirely on how fs.readFile decides to treat the function parameter.

    In JavaScript, you can execute a function asynchronously using for example setTimeout.

    Discussion and resources:

    How does node.js implement non-blocking I/O?

    Concurrency model and Event Loop

    Wikipedia:

    There are two types of callbacks, differing in how they control data flow at runtime: blocking callbacks (also known as synchronous callbacks or just callbacks) and deferred callbacks (also known as asynchronous callbacks).

提交回复
热议问题