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/02-promise-basics/article.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -196,7 +196,7 @@ promise.then(alert); // نشان میدهد "done!" بعد از 1 ثانیه
196
196
197
197
### متدِ catch
198
198
199
-
If we're interested only in errors, then we can use `null` as the first argument: `.then(null, errorHandlingFunction)`. Or we can use `.catch(errorHandlingFunction)`, which is exactly the same:
199
+
اگر فقط به خطاها علاقهمند هستیم، میتوانیم از `null` به عنوان اولین آرگومان استفاده کنیم: `then(null، errorHandlingFunction).`. یا میتوانیم از `catch(errorHandlingFunction).` استفاده کنیم که دقیقاً مشابه است:
200
200
201
201
202
202
```js run
@@ -206,32 +206,32 @@ let promise = new Promise((resolve, reject) => {
206
206
207
207
*!*
208
208
// .catch(f) is the same as promise.then(null, f)
209
-
promise.catch(alert); // shows "Error: Whoops!" after 1 second
209
+
promise.catch(alert); // .را بعد از 1 ثانیه نشان میدهد "Error: Whoops!" خطای
210
210
*/!*
211
211
```
212
212
213
-
The call `.catch(f)` is a complete analog of `.then(null, f)`, it's just a shorthand.
213
+
فراخوانی `catch(f).` یک تشابه کامل از `then(null, f).` است. این فقط یک کوتاه نویسی است.
214
214
215
-
### finally
215
+
### متدِ finally
216
216
217
-
Just like there's a `finally` clause in a regular `try {...} catch {...}`, there's `finally` in promises.
217
+
درست مانند یک بند `finally` در یک `catch {...} try {...}` معمولی، در وعدهها(promises) نیز `finally` وجود دارد.
218
218
219
-
The call `.finally(f)` is similar to `.then(f, f)` in the sense that `f` always runs when the promise is settled: be it resolve or reject.
219
+
فراخوانی `finally(f).` شبیه به `then(f, f).` است به این معنا که `f` همیشه زمانی که وعده(promise) تسویه(settled) میشود اجرا میشود: خواه حلوفصل(resolve) یا رد(reject) شود.
220
220
221
-
`finally` is a good handler for performing cleanup, e.g. stopping our loading indicators, as they are not needed anymore, no matter what the outcome is.
221
+
متدِ `finally` یک کنترلکننده خوب برای انجام پاکسازی است، به عنوان مثال. نشانگرهای بارگیری(loading indicators) خود را متوقف میکنیم، زیرا بدون توجه به نتیجه، دیگر به آنها نیازی نیست.
222
222
223
-
Like this:
223
+
مثل این:
224
224
225
225
```js
226
226
new Promise((resolve, reject) => {
227
-
/* do something that takes time, and then call resolve/reject */
227
+
/* را فراخوانی کنید resolve/reject کاری را انجام دهید که زمان میبرد و سپس */
228
228
})
229
229
*!*
230
-
// runs when the promise is settled, doesn't matter successfully or not
231
-
.finally(() => stop loading indicator)
232
-
// so the loading indicator is always stopped before we process the result/error
230
+
// زمانی اجرا میشود که وعده تسویه شود، مهم نیست موفقیتآمیز باشد یا نه
231
+
.finally(() => توقف نشانهگر بارگیری)
232
+
// بنابراین نشانگر بارگیری همیشه قبل از پردازش نتیجه/خطا متوقف میشود
233
233
*/!*
234
-
.then(result => show result, err => show error)
234
+
.then(result => نمایش نتیجه, err => نمایش خطا)
235
235
```
236
236
237
237
That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are few subtle differences:
0 commit comments