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
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,10 +245,10 @@ new Promise((resolve, reject) => {
245
245
setTimeout(() => resolve("result"), 2000)
246
246
})
247
247
.finally(() => alert("Promise ready"))
248
-
.then(result => alert(result)); // <-- .then handles the result
248
+
.then(result => alert(result)); // <-- نتیجه را اجرا میکند .then
249
249
```
250
250
251
-
And here there's an error in the promise, passed through `finally` to `catch`:
251
+
:پاس داده میشود `catch` به `finally` و در اینجا یک خطایی در وعده وجود دارد که از
252
252
253
253
```js run
254
254
new Promise((resolve, reject) => {
@@ -258,27 +258,27 @@ new Promise((resolve, reject) => {
258
258
.catch(err => alert(err)); // <-- .catch handles the error object
259
259
```
260
260
261
-
That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.
261
+
این بسیار راحت است، زیرا `finally` به معنای پردازش یک نتیجه وعده(promise) نیست. بنابراین از آن عبور میکند.
262
262
263
-
We'll talk more about promise chaining and result-passing between handlers in the next chapter.
263
+
در فصل بعدی بیشتر در مورد زنجیره وعده(promise) و انتقال نتیجه بین اجراکنندگان صحبت خواهیم کرد.
264
264
265
265
266
-
````smart header="We can attach handlers to settled promises"
267
-
If a promise is pending, `.then/catch/finally` handlers wait for it. Otherwise, if a promise has already settled, they just run:
266
+
````smart header="ما می توانیم اجراکنندهها را به وعدههای تسویهشده متصل کنیم"
267
+
اگر وعدهای در حال تعلیق است، اجراکنندگان `then/catch/finally.` منتظر آن هستند. در غیر این صورت، اگر وعدهای قبلاً تسویه شده باشد، آنها فقط اجرا می کنند:
268
268
269
269
```js run
270
-
// the promise becomes resolved immediately upon creation
270
+
// وعده بلافاصله پس از ایجاد حلوفصل میشود
271
271
let promise = new Promise(resolve => resolve("done!"));
272
272
273
-
promise.then(alert); // done! (shows up right now)
273
+
promise.then(alert); // done! (همین الآن نشان میدهد)
274
274
```
275
275
276
-
Note that this makes promises more powerful than the real life "subscription list" scenario. If the singer has already released their song and then a person signs up on the subscription list, they probably won't receive that song. Subscriptions in real life must be done prior to the event.
276
+
توجه داشته باشید که این باعث میشود وعدهها قدرتمندتر از سناریوی واقعی "فهرست اشتراک" باشد. اگر خواننده قبلا آهنگ خود را منتشر کرده باشد و سپس شخصی در لیست اشتراک ثبت نام کند، احتمالاً آن آهنگ را دریافت نخواهد کرد. اشتراک در دنیای واقعی باید قبل از رویداد انجام شود.
277
277
278
-
Promises are more flexible. We can add handlers any time: if the result is already there, they just execute.
278
+
وعدهها انعطافپذیرتر هستند. ما می توانیم هر زمان که بخواهیم اجراکنندگان را اضافه کنیم: اگر نتیجه از قبل وجود داشته باشد، آنها فقط اجرا میشوند.
279
279
````
280
280
281
-
Next, let's see more practical examples of how promises can help us write asynchronous code.
281
+
در مرحله بعد، بیایید نمونههای عملی بیشتری را ببینیم که چگونه وعدهها میتوانند به ما در نوشتن کد ناهمزمان کمک کنند.
0 commit comments