Spelling
Fixed some more minor spelling errors
This commit is contained in:
parent
c97f53563c
commit
2a17f01575
3 changed files with 5 additions and 5 deletions
|
@ -34,7 +34,7 @@ When the executor finishes the job, it should call one of:
|
||||||
- `resolve(value)` -- to indicate that the job finished successfully:
|
- `resolve(value)` -- to indicate that the job finished successfully:
|
||||||
- sets `state` to `"fulfilled"`,
|
- sets `state` to `"fulfilled"`,
|
||||||
- sets `result` to `value`.
|
- sets `result` to `value`.
|
||||||
- `reject(error)` -- to indicate that an error occured:
|
- `reject(error)` -- to indicate that an error occurred:
|
||||||
- sets `state` to `"rejected"`,
|
- sets `state` to `"rejected"`,
|
||||||
- sets `result` to `error`.
|
- sets `result` to `error`.
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ The syntax of `.then` is:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
promise.then(
|
promise.then(
|
||||||
function(result) { /* handle a sucessful result */ },
|
function(result) { /* handle a successful result */ },
|
||||||
function(error) { /* handle an error */ }
|
function(error) { /* handle an error */ }
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
|
@ -207,7 +207,7 @@ class Thenable {
|
||||||
}
|
}
|
||||||
then(resolve, reject) {
|
then(resolve, reject) {
|
||||||
alert(resolve); // function() { native code }
|
alert(resolve); // function() { native code }
|
||||||
// resolve with this.num*2 after the 1 secound
|
// resolve with this.num*2 after the 1 second
|
||||||
setTimeout(() => resolve(this.num * 2), 1000); // (**)
|
setTimeout(() => resolve(this.num * 2), 1000); // (**)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,7 @@ new Promise(function(resolve, reject) {
|
||||||
/* never runs here */
|
/* never runs here */
|
||||||
}).catch(error => { // (**)
|
}).catch(error => { // (**)
|
||||||
|
|
||||||
alert(`The unknown error has occured: ${error}`);
|
alert(`The unknown error has occurred: ${error}`);
|
||||||
// don't return anything => execution goes the normal way
|
// don't return anything => execution goes the normal way
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -295,4 +295,4 @@ The `await` keyword before a promise makes JavaScript wait until that promise se
|
||||||
|
|
||||||
Together they provide a great framework to write asynchronous code that is easy both to read and write.
|
Together they provide a great framework to write asynchronous code that is easy both to read and write.
|
||||||
|
|
||||||
With `async/await` we rarely need to write `promise.then/catch`, but we still shouldn't forget that they are based on promises, because sometimes (e.g. in the outmost scope) we have to use these methods. Also `Promise.all` is a nice thing to wait for many tasks simultaneously.
|
With `async/await` we rarely need to write `promise.then/catch`, but we still shouldn't forget that they are based on promises, because sometimes (e.g. in the outermost scope) we have to use these methods. Also `Promise.all` is a nice thing to wait for many tasks simultaneously.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue