Skip to content

Clarify finally only "passing through" #3061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion 1-js/11-async/02-promise-basics/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are
For instance, here the result is passed through `finally` to `then`:
```js run
new Promise((resolve, reject) => {
setTimeout(() => resolve("result"), 2000)
setTimeout(() => resolve("result"), 2000);
})
.finally(() => alert("Promise ready"))
.then(result => alert(result)); // <-- .then handles the result
Expand All @@ -260,6 +260,18 @@ That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are

That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.

However, if `finally` throws an error, that promise will be rejected with that value instead.

```js run
new Promise((resolve, reject) => {
setTimeout(() => resolve("result"), 1000);
})
*!*
.finally(() => { throw new Error("error"); })
*/!*
.catch((err) => alert(err)); // <-- .catch handles the error object
```

We'll talk more about promise chaining and result-passing between handlers in the next chapter.


Expand Down