Skip to content

Commit 8337d91

Browse files
authored
Merge pull request #120 from kiniggit/master
Promises chaining
2 parents b49fe5f + 4cb3c73 commit 8337d91

File tree

8 files changed

+100
-264
lines changed

8 files changed

+100
-264
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
The short answer is: **no, they are not the equal**:
1+
A resposta breve é: **não, eles não são iguais**:
22

3-
The difference is that if an error happens in `f1`, then it is handled by `.catch` here:
3+
A diferença é que se um erro ocorrer em `f1` ele será tratado pelo `.catch` neste caso:
44

55
```js run
66
promise
77
.then(f1)
88
.catch(f2);
99
```
1010

11-
...But not here:
11+
...Mas não neste:
1212

1313
```js run
1414
promise
1515
.then(f1, f2);
1616
```
1717

18-
That's because an error is passed down the chain, and in the second code piece there's no chain below `f1`.
18+
Isso é devido ao erro ser propagado pela cadeia, e no segundo código não há cadeia após `f1`.
1919

20-
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.
20+
Em outras palavras, `.then` passa resultados/erros para o próximo `.then/catch`. Então, no primeiro exemplo, há um `catch` em seguida, e no segundo exemplo não há, então o erro não é tratado.

1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Promise: then versus catch
1+
# Promessa: then versus catch
22

3-
Are these code fragments equal? In other words, do they behave the same way in any circumstances, for any handler functions?
3+
Estes fragmentos de código são iguais? Em outras palavras, eles se comportam da mesma maneira, em quaisquer circunstâncias, para qualquer função tratadora?
44

55
```js
66
promise.then(f1).catch(f2);

1-js/11-async/03-promise-chaining/article.md

Lines changed: 88 additions & 108 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function getMessage() {
2-
return "Hello, world!";
2+
return "Olá, mundo!";
33
}

1-js/11-async/03-promise-chaining/head.html

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,11 @@
55
script.src = src;
66

77
script.onload = () => resolve(script);
8-
script.onerror = () => reject(new Error("Script load error: " + src));
8+
script.onerror = () => reject(new Error("Erro ao carregar script: " + src));
99

1010
document.head.append(script);
1111
});
1212
}
13-
14-
class HttpError extends Error {
15-
constructor(response) {
16-
super(`${response.status} for ${response.url}`);
17-
this.name = 'HttpError';
18-
this.response = response;
19-
}
20-
}
21-
22-
function loadJson(url) {
23-
return fetch(url)
24-
.then(response => {
25-
if (response.status == 200) {
26-
return response.json();
27-
} else {
28-
throw new HttpError(response);
29-
}
30-
})
31-
}
3213
</script>
3314

3415
<style>

1-js/11-async/03-promise-chaining/promise-handler-variants.svg

Lines changed: 1 addition & 58 deletions
Loading
Lines changed: 1 addition & 38 deletions
Loading
Lines changed: 1 addition & 32 deletions
Loading

0 commit comments

Comments
 (0)