mirror of
https://github.com/xfarrow/javascript-tutorials.git
synced 2025-04-18 20:37:19 +02:00
update
This commit is contained in:
parent
52562f6f1e
commit
0e85666f23
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
The function passed to Promise is called "executor"
|
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
|
When the Promise ends, the callback function should
|
||||||
either call the "resolve" or "reject" callbacks:
|
either call the "resolve" or "reject" callbacks:
|
||||||
resolve(value) — if the job is finished successfully, with result value.
|
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 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 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(
|
promise.then(
|
||||||
result => console.log('The operation was successful. It returned ' + result),
|
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
|
may not be possible to execute now, it is put in the Event Loop. Let's look at
|
||||||
some examples:
|
some examples:
|
||||||
|
|
||||||
1.
|
**Example 1**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
setTimeout(() => console.log('test'), 1000);
|
setTimeout(() => console.log('test'), 1000);
|
||||||
```
|
```
|
||||||
`console.log('test')` will be put in the Event Loop.
|
`console.log('test')` will be put in the Event Loop.
|
||||||
|
|
||||||
2.
|
**Example 2**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const promise = new Promise(function (resolve, reject) {
|
const promise = new Promise(function (resolve, reject) {
|
||||||
console.log('test');
|
console.log('test');
|
||||||
resolve();
|
resolve();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('test2');
|
console.log('test2');
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user