3 ms·
Behind the scenes, no call happens instantly -- it only appears instant if the call is blocking at the source code level. There is no guarantee that in the fut
by doublerebel 13y ago
Behind the scenes, no call happens instantly -- it only appears instant if the call is blocking at the source code level.
There is no guarantee that in the future the compiler/CPU will prevent other actions during a 'blocking' call. Blocking syntax is simply for the convenience of program structure.
Whether the call is blocking/synchronous or non-blocking/asynchronous is just a decision that was made at the language design level. Hence why node has both sync and async for file I/O.
Await/yield allows us to keep the concerns of the function in one code block rather than splitting them up -- regardless of whether the source author wrote the method as 'synchronous'.
Thinking about a program as async from the start avoids a ton of problems down the line.