4 ms·
If you're waiting, it's not synchronous by definition. It's already an asynchronous function.
by dbbk 5y ago
If you're waiting, it's not synchronous by definition. It's already an asynchronous function.
- toast0 5y agoThis is kind of turning the classical definitions on their head. Synchronous I/O functions don't rerurn until the I/O is complete (or complete enough, anyway). The calling function effectively waits for completion. Asynchronous I/O functions return right away, but completion is signaled elsewhere. The calling function does not have to wait (but it can choose to wait for completion if necessary). Asynchronous messaging may not even provide a completion signal, if you want to know it got there, the other side needs to send an asynchronous message back to confirm. Await/async is confusing enough without redefining terms to mean their opposites.
- endorphine 5y agoYes, exactly what I was thinking. I think that I was confused in the first place because `await` I thought meant "block until this function returns". Whereas it really means: "don't wait, swap me out".
- toast0 5y agoYeah, I think a lot of that is the interface isn't great/the abstraction is leaky and you need to know a lot about the details. Because implementations of async/await seem to usually rely on some sort of thread sharing, await also implies yield, and there's often no or limited preemption. Of course, in Javascript, you don't usually have multiple threads at all (unless you fit into one of the special exemptions that allow multiple threads), so your options are pretty limited.