You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/11-async/08-async-await/article.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,22 +121,22 @@ showAvatar();
121
121
122
122
Destul de curat și ușor de citit, nu? Mult mai bine decât înainte.
123
123
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>.
126
126
127
-
For instance:
127
+
De exemplu:
128
128
129
129
```js run module
130
-
// we assume this code runs at toplevel, inside a module
130
+
// presupunem că acest cod rulează la top-level, în interiorul unui modul
131
131
let response = await fetch('/article/promise-chaining/user.json');
132
132
let user = await response.json();
133
133
134
134
console.log(user);
135
135
```
136
136
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ă.
138
138
139
-
Like this:
139
+
Astfel:
140
140
141
141
```js
142
142
(async () => {
@@ -148,10 +148,10 @@ Like this:
148
148
149
149
````
150
150
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`.
153
153
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:
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.
178
178
````
179
179
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`.:
182
182
183
183
```js run
184
184
class Waiter {
@@ -191,9 +191,9 @@ class Waiter {
191
191
192
192
new Waiter()
193
193
.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)))
195
195
```
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`.
0 commit comments