4 ms·
> My understanding is that async/await is fundamentally synchronous. Your JS code runs on a single thread, as far as you're aware, unless you use workers (brows
by vanderZwan 3y ago
> My understanding is that async/await is fundamentally synchronous. Your JS code runs on a single thread, as far as you're aware, unless you use workers (browser) or child processes (node).
You're talking about paralellism. Concurrency is not parallelism. Synchronous and asynchronous concurrency can both run single-threaded. They behave very differently however.
Asynchronous basically is about offloading work to be automatically resumed at some point in the future - both in the form of currently active code being able to schedule code for later, as well as incoming events being suspended and queued up to be handled after the current bit of code finishes running.
Synchronous concurrency essentially revolves around being able to suspend the current bit of code until explicitly resumed - coroutines are an example, but it may also be in the form of "suspend this code block until a certain event happens", like in Céu.
This has the advantage of being deterministic in behavior (unlike asynchronous code). It also has very low memory overhead compared to other paradigms. This makes it extremely useful in embedded real-time systems, hence the existence of languages like Esterel and Céu specifically with that target in mind[0][1][2].
[0] https://en.wikipedia.org/wiki/Synchronous_programming_language https://en.wikipedia.org/wiki/Synchronous_programming_langua...
[1] https://en.wikipedia.org/wiki/Esterel https://en.wikipedia.org/wiki/Esterel
[2] http://www.ceu-lang.org/ http://www.ceu-lang.org/