Skip to content

Commit 8ce413e

Browse files
authored
finally method
1 parent 0fae38d commit 8ce413e

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

1-js/11-async/02-promise-basics/article.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ promise.then(alert); // نشان می‌دهد "done!" بعد از 1 ثانیه
196196
197197
### متدِ catch
198198
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).` استفاده کنیم که دقیقاً مشابه است:
200200
201201
202202
```js run
@@ -206,32 +206,32 @@ let promise = new Promise((resolve, reject) => {
206206
207207
*!*
208208
// .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!" خطای
210210
*/!*
211211
```
212212
213-
The call `.catch(f)` is a complete analog of `.then(null, f)`, it's just a shorthand.
213+
فراخوانی `catch(f).` یک تشابه کامل از `then(null, f).` است. این فقط یک کوتاه نویسی است.
214214
215-
### finally
215+
### متدِ finally
216216
217-
Just like there's a `finally` clause in a regular `try {...} catch {...}`, there's `finally` in promises.
217+
درست مانند یک بند `finally` در یک `catch {...} try {...}` معمولی، در وعده‌ها(promises) نیز `finally` وجود دارد.
218218
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) شود.
220220
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) خود را متوقف می‌کنیم، زیرا بدون توجه به نتیجه، دیگر به آن‌ها نیازی نیست.
222222
223-
Like this:
223+
مثل این:
224224
225225
```js
226226
new Promise((resolve, reject) => {
227-
/* do something that takes time, and then call resolve/reject */
227+
/* را فراخوانی کنید resolve/reject کاری را انجام دهید که زمان می‌برد و سپس */
228228
})
229229
*!*
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+
// بنابراین نشانگر بارگیری همیشه قبل از پردازش نتیجه/خطا متوقف می‌شود
233233
*/!*
234-
.then(result => show result, err => show error)
234+
.then(result => نمایش نتیجه, err => نمایش خطا)
235235
```
236236
237237
That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are few subtle differences:

0 commit comments

Comments
 (0)