Update as per @paroche's comments
This commit is contained in:
parent
07ae558025
commit
95ddbe45a7
1 changed files with 2 additions and 2 deletions
|
@ -287,7 +287,7 @@ fetch('/article/promise-chaining/user.json')
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
The code works; see comments about the details. However, there's a potential problem in it, a typical error of those who begin to use promises.
|
The code works; see comments about the details. However, there's a potential problem in it, a typical error for those who begin to use promises.
|
||||||
|
|
||||||
Look at the line `(*)`: how can we do something *after* the avatar has finished showing and gets removed? For instance, we'd like to show a form for editing that user or something else. As of now, there's no way.
|
Look at the line `(*)`: how can we do something *after* the avatar has finished showing and gets removed? For instance, we'd like to show a form for editing that user or something else. As of now, there's no way.
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ fetch('/article/promise-chaining/user.json')
|
||||||
|
|
||||||
That is, the `.then` handler in line `(*)` now returns `new Promise`, that becomes settled only after the call of `resolve(githubUser)` in `setTimeout` `(**)`. The next `.then` in the chain will wait for that.
|
That is, the `.then` handler in line `(*)` now returns `new Promise`, that becomes settled only after the call of `resolve(githubUser)` in `setTimeout` `(**)`. The next `.then` in the chain will wait for that.
|
||||||
|
|
||||||
As a good practice, an asynchronous action should always return a promise. That makes it possible to plan actions after it. Even if we don't plan to extend the chain now, we may need it later.
|
As a good practice, an asynchronous action should always return a promise. That makes it possible to plan actions after it; even if we don't plan to extend the chain now, we may need it later.
|
||||||
|
|
||||||
Finally, we can split the code into reusable functions:
|
Finally, we can split the code into reusable functions:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue