Skip to content

Commit 8e7f04f

Browse files
committed
UPDATE
1 parent ca90e8d commit 8e7f04f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

JS/JS-br.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- [Debouncing](#debouncing)
3131
- [Throttle](#throttle)
3232
- [Map、FlatMap e Reduce](#mapflatmap-e-reduce)
33-
- [Async e await](#async-and-await)
33+
- [Async e await](#async-e-await)
3434
- [Proxy](#proxy)
3535
- [Por que 0.1 + 0.2 != 0.3](#why-01--02--03)
3636
- [Expressões regulares](#regular-expressions)
@@ -1237,9 +1237,9 @@ function b() {
12371237
```
12381238
12391239
1240-
# Async and await
1240+
# Async e await
12411241
1242-
`async` function will return a `Promise`:
1242+
A função `async` vai retornar uma `Promise`:
12431243
12441244
```js
12451245
async function test() {
@@ -1248,9 +1248,9 @@ async function test() {
12481248
console.log(test()); // -> Promise {<resolved>: "1"}
12491249
```
12501250
1251-
You can think of `async` as wrapping a function using `Promise.resolve()`.
1251+
Você pode pensar em `async` como uma função encapsuladora usando `Promise.resolve()`.
12521252
1253-
`await` can only be used in `async` functions:
1253+
`await` pode ser usado apenas em funcões `async`:
12541254
12551255
```js
12561256
function sleep() {
@@ -1268,6 +1268,10 @@ async function test() {
12681268
test()
12691269
```
12701270
1271+
O código acime vai exibir `finish` antes de exibir `object`. Porque `await` espera pela funcão `sleep` `resolve`, mesmo se a sincronização de código estiver seguida, ele não executa antes do código assíncrono ser executado.
1272+
1273+
A vantagem do `async` e `await` comparado ao uso direto da `Promise` mente em manipular a cadeia de chamada do `then`, que pode produzir código claro e acurado.
1274+
12711275
The above code will print `finish` before printing `object`. Because `await` waits for the `sleep` function `resolve`, even if the synchronization code is followed, it is not executed before the asynchronous code is executed.
12721276
12731277
The advantage of `async` and `await` compared to the direct use of `Promise` lies in handling the call chain of `then`, which can produce clear and accurate code. The downside is that misuse of `await` can cause performance problems because `await` blocks the code. Perhaps the asynchronous code does not depend on the former, but it still needs to wait for the former to complete, causing the code to lose concurrency.

0 commit comments

Comments
 (0)