3 ms·
All calls aren't async though. You have to tell the compiler/interpreter that the thing you're calling is async by using the await keyword. That's the thing tha
by MatthewPhillips 13y ago
All calls aren't async though. You have to tell the compiler/interpreter that the thing you're calling is async by using the await keyword. That's the thing that I don't love about the C# await, JavaScript yield, etc. If I have to tell the compiler to yield then I still have to think about my program as asynchronous. And if I change a function to do an sync call, I still have to change it's own signature to be async, and anything that calls it, all the way up. So all you're really saving through these keywords is a bit of indentation. I don't really care about the indentation though; I use 2 spaces and just refactor when things get too far to the right.
- doublerebel 13y agoBehind 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.
- kzahel 13y agoI personally love seeing the yield/await syntax before a function call. I don't like using gevent in Python because I feel like it's hiding important information from me. I much prefer actually being explicit about what the program is actually doing.