diff --git a/async-await/1_promises.js b/async-await/1_promises.js index 036ba0d..034267b 100644 --- a/async-await/1_promises.js +++ b/async-await/1_promises.js @@ -2,7 +2,7 @@ /* The function passed to Promise is called "executor" - and gets executed synchronously the moment the Promise is created. + and gets executed synchronously and immediately after the Promise is created. When the Promise ends, the callback function should either call the "resolve" or "reject" callbacks: resolve(value) — if the job is finished successfully, with result value. @@ -24,7 +24,7 @@ const promise = new Promise(function (resolve, reject) { /* The first argument of .then is a function that runs when the promise is resolved and receives the result. The second argument of .then is a function that runs when the promise is rejected and receives the error. - The function passed to "then()" is put in the queue! + The function passed to "then()" is put in the Event Loop queue. */ promise.then( result => console.log('The operation was successful. It returned ' + result), diff --git a/async-await/event-loop.md b/async-await/event-loop.md index 63f14ae..0a1c2a4 100644 --- a/async-await/event-loop.md +++ b/async-await/event-loop.md @@ -9,20 +9,21 @@ respect to the main flow of execution. Whenever we meet a portion of code that may not be possible to execute now, it is put in the Event Loop. Let's look at some examples: -1. +**Example 1** ```javascript setTimeout(() => console.log('test'), 1000); ``` `console.log('test')` will be put in the Event Loop. -2. +**Example 2** + ```javascript const promise = new Promise(function (resolve, reject) { -console.log('test'); -resolve(); + console.log('test'); + resolve(); }).then(() => { -console.log('test2'); + console.log('test2'); }); ```