Skip to content

Commit e968646

Browse files
committed
minor fixes, close #2137
1 parent 165ea83 commit e968646

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

1-js/11-async/02-promise-basics/article.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,12 @@ new Promise((resolve, reject) => {
229229
*!*
230230
// runs when the promise is settled, doesn't matter successfully or not
231231
.finally(() => stop loading indicator)
232+
// so the loading indicator is always stopped before we process the result/error
232233
*/!*
233234
.then(result => show result, err => show error)
234235
```
235236
236-
It's not exactly an alias of `then(f,f)` though. There are several important differences:
237+
That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are few subtle differences:
237238
238239
1. A `finally` handler has no arguments. In `finally` we don't know whether the promise is successful or not. That's all right, as our task is usually to perform "general" finalizing procedures.
239240
2. A `finally` handler passes through results and errors to the next handler.
@@ -257,14 +258,13 @@ It's not exactly an alias of `then(f,f)` though. There are several important dif
257258
.catch(err => alert(err)); // <-- .catch handles the error object
258259
```
259260
260-
That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.
261+
That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.
261262
262-
We'll talk more about promise chaining and result-passing between handlers in the next chapter.
263+
We'll talk more about promise chaining and result-passing between handlers in the next chapter.
263264
264-
3. Last, but not least, `.finally(f)` is a more convenient syntax than `.then(f, f)`: no need to duplicate the function `f`.
265265
266-
````smart header="On settled promises handlers run immediately"
267-
If a promise is pending, `.then/catch/finally` handlers wait for it. Otherwise, if a promise has already settled, they execute immediately:
266+
````smart header="We can attach handlers to settled promises"
267+
If a promise is pending, `.then/catch/finally` handlers wait for it. Otherwise, if a promise has already settled, they just run:
268268
269269
```js run
270270
// the promise becomes resolved immediately upon creation
@@ -273,9 +273,9 @@ let promise = new Promise(resolve => resolve("done!"));
273273
promise.then(alert); // done! (shows up right now)
274274
```
275275
276-
Note that this is different, and more powerful than the real life "subscription list" scenario. If the singer has already released their song and then a person signs up on the subscription list, they probably won't receive that song. Subscriptions in real life must be done prior to the event.
276+
Note that this makes promises more powerful than the real life "subscription list" scenario. If the singer has already released their song and then a person signs up on the subscription list, they probably won't receive that song. Subscriptions in real life must be done prior to the event.
277277
278-
Promises are more flexible. We can add handlers any time: if the result is already there, our handlers get it immediately.
278+
Promises are more flexible. We can add handlers any time: if the result is already there, they just execute.
279279
````
280280

281281
Next, let's see more practical examples of how promises can help us write asynchronous code.

0 commit comments

Comments
 (0)