mirror of
https://github.com/xfarrow/javascript-tutorials.git
synced 2025-04-15 02:52:10 +02:00
update
This commit is contained in:
parent
52562f6f1e
commit
0e85666f23
@ -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),
|
||||
|
@ -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');
|
||||
});
|
||||
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user