Here are my comments. With regard to this:
It takes a function as an argument and that function gets passed two callbacks: one for notifying when the operation is successful (resolve) and one for notifying when the operation has failed (reject).
I would add that these “callbacks” are not the callbacks passed in the then or catch method. They play the roles of event notifiers. In fact, in the early implementations, they were ordinary events and the callbacks in the then and catch methods were event listeners.
With regard to this:
Note that we return a new Promise that takes a function as a parameter. That function starts the asynchronous operation that uses a callback and when it’s done it calls reject(error) if there are errors or resolve(result) if it went well.
This is not clear to me. What I see is that we wrapped the original function to create a new function that returns a promise. Indeed, the wrapped original function receives a fixed special callback as parameter, which calls reject(error) if there are errors or resolve(result) if it went well. However, the promise itself does not receive this special callback (or the executor) as a parameter. So, it’s unclear what is meant by “a new Promise that takes a function as a parameter”.
With regard to this:
Async/await makes your asynchronous code look more synchronous, but it’s not.
Most people say that, but it is misleading. Indeed, the async function is asynchronous — you cannot get the value in the main flow — instead you must use callbacks. However, within the async function the await calls are perfectly synchronous. There is no magic. They cannot behave exactly (within) as synchronous calls and not be (within) exactly synchronous calls.
If a value is computed using asynchronous calls, the overall computation of the value is itself asynchronous. The confusion is perhaps that we feel that the converse must also be true, but it is not true: the async function can be asynchronous and makes perfectly synchronous calls. This is the case. The async function is asynchronous because its implementation uses a generator that is called with the next method, which returns immediately before any subsequent calls to the next method. So the async function returns before we start to execute any call within, but these calls within are themselves perfectly synchronous — there is no magic.
I use this fact to create the construct async/await without promises. I plan to write another version where we have the option to await promises, because it’s nice to be able to await promises. The current version shows that we don’t have to use promises to have async/await.
