3 ms·
You're blending concepts. All parallelism is asynchronous, but not all "asynchrony" is parallel. I have to use Python as as an example since I don't have much
by scuff3d 5mo ago
You're blending concepts. All parallelism is asynchronous, but not all "asynchrony" is parallel.
I have to use Python as as an example since I don't have much experience with JavaScript, but when you're using asyncio, that's single threaded non-blocking IO (asynchronous). Each use of "await" yields execution back to the event loop, and it can can schedule some other task to run. Tasks can run asynchronously, but no in parallel.
When you use the multiprocess library you are actually creating new threads that run in parallel (I'm ignoring the threading library because it just muddies the water). That's also asynchronous execution.
I don't know the semantics as well in JavaScript, but I'm sure the principle is the same. At certain points you can yield to the runtime and it will schedule other pending tasks to execute while the current one is pending.
My point was that mistake I see people make (in Python) is they think of their program in blocking terms by default. So they get this frustrating coloring problem because they are trying to shoehorn in non-blocking calls. If instead you design the application from the start with asyncio in mind, it makes things much simpler.
- coldtea 5mo ago>All parallelism is asynchronous, but not all "asynchrony" is parallel. Sure, but my comment was not about parallelism compared to asynchronous, but about the idea that Javascript is above the "blocking first mindset". Javascript depends on a blocking (single-threaded, run-to-completion) backend. The asynchronicity on top of this blocking layer is an abstraction based on cooperative yielding. Whereas e.g. Erlang's asynchronicity is part of the runtime model itself.
- scuff3d 5mo agoYeah but nothing I said disputed that. Practically all languages have concurrency built on top of an inherently single threaded execution environment. The two standouts are Erlang based languages and Go. My point, coming from Python, was that whenever I can I write the entire application as an asyncio app, which cuts down on the function coloring problem. That doesn't mean you don't have to be careful, it's super easy to accidentally block the event loop.