Skip to content

Commit 8e97dfc

Browse files
committed
translated until line 196
1 parent 8613a17 commit 8e97dfc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

1-js/11-async/08-async-await/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ showAvatar();
121121
122122
Destul de curat și ușor de citit, nu? Mult mai bine decât înainte.
123123
124-
````smart header="Modern browsers allow top-level `await` in modules"
125-
In modern browsers, `await` on top level works just fine, when we're inside a module. We'll cover modules in article <info:modules-intro>.
124+
````smart header="Browserele moderne permit top-level `await` în module"
125+
În browserele moderne, top-level `await` funcționează chiar bine, atunci când ne aflăm în interiorul unui modul. Vom aborda modulele în articolul <info:modules-intro>.
126126
127-
For instance:
127+
De exemplu:
128128
129129
```js run module
130-
// we assume this code runs at top level, inside a module
130+
// presupunem că acest cod rulează la top-level, în interiorul unui modul
131131
let response = await fetch('/article/promise-chaining/user.json');
132132
let user = await response.json();
133133
134134
console.log(user);
135135
```
136136
137-
If we're not using modules, or [older browsers](https://caniuse.com/mdn-javascript_operators_await_top_level) must be supported, there's a universal recipe: wrapping into an anonymous async function.
137+
Dacă nu folosim module, sau [browsere mai vechi](https://caniuse.com/mdn-javascript_operators_await_top_level) trebuie să fie suportate, există o rețetă universală: înfășurarea într-o funcție asincronă anonimă.
138138
139-
Like this:
139+
Astfel:
140140
141141
```js
142142
(async () => {
@@ -148,10 +148,10 @@ Like this:
148148
149149
````
150150

151-
````smart header="`await` accepts \"thenables\""
152-
Like `promise.then`, `await` allows us to use thenable objects (those with a callable `then` method). The idea is that a third-party object may not be a promise, but promise-compatible: if it supports `.then`, that's enough to use it with `await`.
151+
````smart header="`await` acceptă \"thenables\""
152+
La fel ca `promise.then`, `await` ne permite să folosim obiecte thenable (cele care au o metodă `then` apelabilă). Ideea este că un obiect terț poate să nu fie o promisiune, dar să fie compatibil cu promisiunile: dacă acceptă `.then`, este suficient pentru a-l folosi cu `await`.
153153

154-
Here's a demo `Thenable` class; the `await` below accepts its instances:
154+
Iată o clasă demo `Thenable`; `await` de mai jos acceptă instanțele sale:
155155

156156
```js run
157157
class Thenable {
@@ -160,25 +160,25 @@ class Thenable {
160160
}
161161
then(resolve, reject) {
162162
alert(resolve);
163-
// resolve with this.num*2 after 1000ms
163+
// rezolvă cu this.num*2 după 1000ms
164164
setTimeout(() => resolve(this.num * 2), 1000); // (*)
165165
}
166166
}
167167

168168
async function f() {
169-
// waits for 1 second, then result becomes 2
169+
// așteaptă 1 secundă, apoi result devine 2
170170
let result = await new Thenable(1);
171171
alert(result);
172172
}
173173

174174
f();
175175
```
176176

177-
If `await` gets a non-promise object with `.then`, it calls that method providing the built-in functions `resolve` and `reject` as arguments (just as it does for a regular `Promise` executor). Then `await` waits until one of them is called (in the example above it happens in the line `(*)`) and then proceeds with the result.
177+
Dacă `await` obține un obiect non-promise cu `.then`, apelează metoda respectivă oferind ca argumente funcțiile integrate `resolve` și `reject` (la fel cum o face în cazul unui executor `Promise` obișnuit). Apoi `await` așteaptă până când una dintre ele este apelată (în exemplul de mai sus se întâmplă în linia `(*)`) și apoi continuă cu rezultatul.
178178
````
179179
180-
````smart header="Async class methods"
181-
To declare an async class method, just prepend it with `async`:
180+
````smart header="Metode de clasă asincrone"
181+
Pentru a declara o metodă de clasă asincronă, trebuie doar să o precedați cu `async`.:
182182
183183
```js run
184184
class Waiter {
@@ -191,9 +191,9 @@ class Waiter {
191191
192192
new Waiter()
193193
.wait()
194-
.then(alert); // 1 (this is the same as (result => alert(result)))
194+
.then(alert); // 1 (acesta este același cu (result => alert(result)))
195195
```
196-
The meaning is the same: it ensures that the returned value is a promise and enables `await`.
196+
Semnificația este aceeași: se asigură că valoarea returnată este o promisiune și permite `await`.
197197
198198
````
199199
## Error handling

0 commit comments

Comments
 (0)