Remix.run Logo
IshKebab 2 days ago

Everything is not async by default in JS.

fzzzy 2 days ago | parent | next [-]

I think what they mean is that there are no blocking functions in the standard library except alert, prompt, and confirm. ( are there any others?)

steve_adams_86 2 days ago | parent [-]

Yeah, you can call async functions without specifying it as such and the script will just carry on regardless of how you're handling it. Totally weird, but also pretty cool. When I first started some 20 years ago that was a major foot gun for me, coming from PHP where functions always returned before the next one was called.

throwawayffffas 2 days ago | parent | prev [-]

I mean everything is running on the runloop, async/await, promises, and callbacks are different flavors of syntactic sugar for the same underlying thing.

In JS you can do:

   async function foo(){...}
   function bar(){foo().then(...);}
In python though async and sync code runs in a fundamentally different way as far as I understand it.
IshKebab 2 days ago | parent [-]

I'm not too familiar with Python async. The only time I used it was to get stderr and stdout out of a subprocess.run() separately. I think anyone using it for performance reasons is insane and should just switch to a more performant language.

Anyway I think the main difference is that in Python you control the event loop whereas in JS there's one fixed event loop and you have no choice about it.