Skip to content

Promises chaining #194

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

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
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: 7 additions & 7 deletions 1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
The short answer is: **no, they are not equal**:
Stručná odpověď zní: **ne, nejsou ekvivalentní**:

The difference is that if an error happens in `f1`, then it is handled by `.catch` here:
Rozdíl je v tom, že pokud ve `f1` nastane chyba, je zde ošetřena funkcí `.catch`:

```js run
promise
příslib
.then(f1)
.catch(f2);
```

...But not here:
...Ale zde ne:

```js run
promise
příslib
.then(f1, f2);
```

That's because an error is passed down the chain, and in the second code piece there's no chain below `f1`.
Je to proto, že chyba je předána řetězem, ale ve druhém uvedeném kódu za `f1` žádný řetěz není.

In other words, `.then` passes results/errors to the next `.then/catch`. So in the first example, there's a `catch` below, and in the second one there isn't, so the error is unhandled.
Jinými slovy, `.then` předá výsledky nebo chyby dalšímu `.then/catch`. V prvním příkladu je za ním `catch`, ale ve druhém není, takže chyba zůstane neošetřena.
10 changes: 5 additions & 5 deletions 1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Promise: then versus catch
# Příslib: then oproti catch

Are these code fragments equal? In other words, do they behave the same way in any circumstances, for any handler functions?
Jsou tyto fragmenty kódu ekvivalentní? Jinými slovy, chovají se zcela stejně za každých okolností a pro jakékoli handlery?

```js
promise.then(f1).catch(f2);
příslib.then(f1).catch(f2);
```

Versus:
Oproti:

```js
promise.then(f1, f2);
příslib.then(f1, f2);
```
374 changes: 187 additions & 187 deletions 1-js/11-async/03-promise-chaining/article.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions 1-js/11-async/03-promise-chaining/head.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script>
function loadScript(src) {
function načtiSkript(src) {
return new Promise(function(resolve, reject) {
let script = document.createElement('script');
script.src = src;
let skript = document.createElement('script');
skript.src = src;

script.onload = () => resolve(script);
script.onerror = () => reject(new Error("Script load error: " + src));
skript.onload = () => resolve(skript);
skript.onerror = () => reject(new Error("Chyba při načítání skriptu: " + src));

document.head.append(script);
document.head.append(skript);
});
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion 1-js/11-async/03-promise-chaining/one.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function one() {
function jedna() {
alert(1);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading