3 ms·
If I have a bunch of node code, can I execute it in C# from the command line on a linux box without changing the code at all? Also the async/await stuff doesn'
by dools 5y ago
If I have a bunch of node code, can I execute it in C# from the command line on a linux box without changing the code at all?
Also the async/await stuff doesn't really make node synchronous, because you still have to wrap your await in an asynchronous function.
I use sync versions of library methods and sync-request to make things synchronous, but I'm just wondering what the process would be to "disable" the asynchronous behaviour of nodejs and make everything blocking by default.
- smt88 5y ago> If I have a bunch of node code, can I execute it in C# from the command line on a linux box without changing the code at all? No, C# is a different language. The syntax should be familiar to someone who has written JavaScript (especially TypeScript), Java, or any C-like language. > Also the async/await stuff doesn't really make node synchronous, because you still have to wrap your await in an asynchronous function. No, you don't[1]. But even when you did, what's the difference to you? You can just wrap all the way up to the top level. The node CLI doesn't care if it's executing a top-level async function or not. You could have async/await syntax available to every line of code you write. > I'm just wondering what the process would be to "disable" the asynchronous behaviour of nodejs and make everything blocking by default Part of the reason Node has asynchronous* behavior is because it's part of the ECMAScript standard. So to answer your question, to disable the asynchronous code, you would have to either: A) Stop using any libraries that use callbacks or return promises B) Stop using JavaScript That's why I suggested C#. It doesn't make sense to say, "How hard would it be to change this fundamental design decision in this language?" If you don't like it, just use another language. Or use the built-in syntactical sugar (async/await) that make it feel like a synchronous language. 1. https://pprathameshmore.medium.com/top-level-await-support-in-node-js-v14-3-0-8af4f4a4d478 https://pprathameshmore.medium.com/top-level-await-support-i... * I am aware that JavaScript is single-threaded and blocking, but I'm using "asynchronous" as shorthand for "programming in an asynchronous style".
- dools 5y agoOkay so top level await now let’s you stick await in front of anything you want to block… so what about a change to the runtime that just defaulted to that? Also Google Apps Script has a blocking v8 runtime so I’m pretty sure that what I’m asking for isn’t some sort of oxymoron or logical impossibility