3 ms·
I think it was a good question, seeing all the various answers people gave trying to explain and clarify. I enjoyed the discussion, and it helped deepen my unde
by lioeters 5y ago
I think it was a good question, seeing all the various answers people gave trying to explain and clarify. I enjoyed the discussion, and it helped deepen my understanding.
As you said in another comment, what's confusing is that "await" actually means "Don't wait for the result, continue running other instructions, then come back to resume when the result is ready."
> Async operations like promises are put into an event queue, which runs after the main thread has finished processing so that they do not block subsequent JavaScript code from running. The queued operations will complete as soon as possible then return their results to the JavaScript environment.
From: General asynchronous programming concepts - https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Concepts https://developer.mozilla.org/en-US/docs/Learn/JavaScript/As...
---
About how async functions can be "paused and continued", it relates to the general concept of "continuations", which are:
> ..constructs that give a programming language the ability to save the execution state at any point and return to that point at a later point in the program, possibly multiple times.
> ..In C#, async and await "sign up the rest of method as the continuation, and then return to your caller immediately; the task will invoke the continuation when it completes."
https://en.wikipedia.org/wiki/Continuation https://en.wikipedia.org/wiki/Continuation