From 5daaa740233636780dadcef3eb43196c6eef799b Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Sun, 16 Jan 2022 13:17:52 +0330 Subject: [PATCH 01/28] promise --- 1-js/11-async/02-promise-basics/article.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index f2f533220..186250819 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -1,15 +1,15 @@ -# Promise +# وعده (promise) -Imagine that you're a top singer, and fans ask day and night for your upcoming song. +تصور کنید که یک خواننده برتر هستید و طرفداران شب و روز درخواست آهنگ بعدی شما را دارند. -To get some relief, you promise to send it to them when it's published. You give your fans a list. They can fill in their email addresses, so that when the song becomes available, all subscribed parties instantly receive it. And even if something goes very wrong, say, a fire in the studio, so that you can't publish the song, they will still be notified. +برای اینکه کمی راحت بشوید، قول می‌دهید پس از انتشار آن را برای آن‌ها ارسال کنید. شما یک لیست به طرفداران خود می‌دهید. آن‌ها می‌توانند آدرس ایمیل خود را پر کنند، به طوری که وقتی آهنگ در دسترس قرار گرفت، همه دنبال‌ کننده‌ها فورا آن را دریافت کنند. و حتی اگر مشکلی پیش بیاید، فرض کنید آتش سوزی در استودیو، به طوری که نتوانید آهنگ را منتشر کنید، باز هم به آن‌ها اطلاع داده خواهد شد. -Everyone is happy: you, because the people don't crowd you anymore, and fans, because they won't miss the song. +همه خوشحال هستند: شما، چون مردم دیگر مزاحم شما نمی‌شوند، و طرفداران، چون آهنگ را از دست نمی‌دهند. -This is a real-life analogy for things we often have in programming: +این یک تشبیه واقعی برای چیزهایی است که اغلب در برنامه‌نویسی داریم: -1. A "producing code" that does something and takes time. For instance, some code that loads the data over a network. That's a "singer". -2. A "consuming code" that wants the result of the "producing code" once it's ready. Many functions may need that result. These are the "fans". +1. یک "کد تولید‌کننده" که کاری انجام می‌دهد و زمانی می‌برد. به عنوان مثال، کدهایی که داده‌ها را از طریق شبکه بارگیری می‌کند. این یک "خواننده" است. +2. یک "کد مصرف‌کننده" که نتیجه‌ی "کد تولیدکننده" را پس از آماده شدن می خواهد. بسیاری از توابع ممکن است به آن نتیجه نیاز داشته باشند. اینها "طرفداران" هستند. 3. A *promise* is a special JavaScript object that links the "producing code" and the "consuming code" together. In terms of our analogy: this is the "subscription list". The "producing code" takes whatever time it needs to produce the promised result, and the "promise" makes that result available to all of the subscribed code when it's ready. The analogy isn't terribly accurate, because JavaScript promises are more complex than a simple subscription list: they have additional features and limitations. But it's fine to begin with. From a42e936485ec3dea8727471bbe31b39f601b40af Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Mon, 17 Jan 2022 20:36:04 +0330 Subject: [PATCH 02/28] syntax --- 1-js/11-async/02-promise-basics/article.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index 186250819..8e19b5149 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -2,7 +2,7 @@ تصور کنید که یک خواننده برتر هستید و طرفداران شب و روز درخواست آهنگ بعدی شما را دارند. -برای اینکه کمی راحت بشوید، قول می‌دهید پس از انتشار آن را برای آن‌ها ارسال کنید. شما یک لیست به طرفداران خود می‌دهید. آن‌ها می‌توانند آدرس ایمیل خود را پر کنند، به طوری که وقتی آهنگ در دسترس قرار گرفت، همه دنبال‌ کننده‌ها فورا آن را دریافت کنند. و حتی اگر مشکلی پیش بیاید، فرض کنید آتش سوزی در استودیو، به طوری که نتوانید آهنگ را منتشر کنید، باز هم به آن‌ها اطلاع داده خواهد شد. +برای اینکه کمی راحت بشوید، قول می‌دهید پس از انتشار آن را برای آن‌ها ارسال کنید. شما یک لیست به طرفداران خود می‌دهید. آن‌ها می‌توانند آدرس ایمیل خود را پر کنند، به طوری که وقتی آهنگ در دسترس قرار گرفت، همه مشترکین فورا آن را دریافت کنند. و حتی اگر مشکلی پیش بیاید، فرض کنید آتش سوزی در استودیو، به طوری که نتوانید آهنگ را منتشر کنید، باز هم به آن‌ها اطلاع داده خواهد شد. همه خوشحال هستند: شما، چون مردم دیگر مزاحم شما نمی‌شوند، و طرفداران، چون آهنگ را از دست نمی‌دهند. @@ -10,11 +10,11 @@ 1. یک "کد تولید‌کننده" که کاری انجام می‌دهد و زمانی می‌برد. به عنوان مثال، کدهایی که داده‌ها را از طریق شبکه بارگیری می‌کند. این یک "خواننده" است. 2. یک "کد مصرف‌کننده" که نتیجه‌ی "کد تولیدکننده" را پس از آماده شدن می خواهد. بسیاری از توابع ممکن است به آن نتیجه نیاز داشته باشند. اینها "طرفداران" هستند. -3. A *promise* is a special JavaScript object that links the "producing code" and the "consuming code" together. In terms of our analogy: this is the "subscription list". The "producing code" takes whatever time it needs to produce the promised result, and the "promise" makes that result available to all of the subscribed code when it's ready. +3. یک *وعده* (*promise*) یک شیء خاص جاوااسکریپت است که "کد تولید‌کننده" و "کد مصرف‌کننده" را به یکدیگر پیوند می‌دهد. از نظر تشبیه ما: این فهرست اشتراک است. "کد تولید‌کننده" هر زمانی را که برای تولید نتیجه وعده داده شده نیاز دارد طول می‌کشد، و "وعده" (promise) آن نتیجه را پس از آماده شدن برای همه کدهای مشترک شده در دسترس قرار می‌دهد. -The analogy isn't terribly accurate, because JavaScript promises are more complex than a simple subscription list: they have additional features and limitations. But it's fine to begin with. +این تشبیه خیلی دقیق نیست، زیرا وعده‌های (promises) جاوا‌اسکریپت پیچیده‌تر از یک لیست اشتراک ساده است: آن‌ها دارای ویژگی‌ها و محدودیت‌های اضافی هستند. اما برای شروع خوب است. -The constructor syntax for a promise object is: +نحوِ (syntax) سازنده برای یک شیء وعده (promise) به صورت زیر است: ```js let promise = new Promise(function(resolve, reject) { From f18594f1c26e8049a37956f7f48d96b5baff5dca Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Wed, 19 Jan 2022 22:07:37 +0330 Subject: [PATCH 03/28] resolve and reject --- 1-js/11-async/02-promise-basics/article.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index 8e19b5149..d0d634eee 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -22,16 +22,16 @@ let promise = new Promise(function(resolve, reject) { }); ``` -The function passed to `new Promise` is called the *executor*. When `new Promise` is created, the executor runs automatically. It contains the producing code which should eventually produce the result. In terms of the analogy above: the executor is the "singer". +تابعی که به `new Promise` ارسال می‌شود *اجرا‌کننده* نامیده می‌شود. هنگامی که `new Promise` ایجاد می‌شود، اجرا‌کننده به طور خودکار اجرا می‌شود. این شامل کد تولید‌کننده است که در نهایت باید نتیجه را ایجاد کند. از نظر تشبیه بالا: اجراکننده "خواننده" است. -Its arguments `resolve` and `reject` are callbacks provided by JavaScript itself. Our code is only inside the executor. +آرگومان‌های آن `resolve` و `reject` فراخوان‌هایی هستند که توسط خود جاوا‌اسکریپت ارائه شده است. کد ما فقط در داخل اجرا‌کننده است. -When the executor obtains the result, be it soon or late, doesn't matter, it should call one of these callbacks: +وقتی اجرا‌کننده به نتیجه رسید، چه زود باشد چه دیر، مهم نیست، باید یکی از این callback ها را فراخوانی کند: -- `resolve(value)` — if the job is finished successfully, with result `value`. -- `reject(error)` — if an error has occurred, `error` is the error object. +- `resolve(value)` — `value` اگر کار با موفقیت به پایان رسید، با نتیجه‌ی. +- `reject(error)` — همان شیء خطا است `error` ، اگر خطایی رخ داده باشد -So to summarize: the executor runs automatically and attempts to perform a job. When it is finished with the attempt, it calls `resolve` if it was successful or `reject` if there was an error. +بنابراین به طور خلاصه: اجراکننده به طور خودکار اجرا می‌شود و تلاش می‌کند تا یک کار را انجام دهد. هنگامی که کار با تلاش به پایان رسید، در صورت موفقیت‌آمیز بودن، `resolve` یا در صورت وجود هر خطایی `reject` را فراخوانی می‌کند. The `promise` object returned by the `new Promise` constructor has these internal properties: From db7e5050ea5fa01ed34c916206e253e6b6f80035 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Fri, 21 Jan 2022 11:51:26 +0330 Subject: [PATCH 04/28] takes time --- 1-js/11-async/02-promise-basics/article.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index d0d634eee..c5f50c001 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -33,18 +33,18 @@ let promise = new Promise(function(resolve, reject) { بنابراین به طور خلاصه: اجراکننده به طور خودکار اجرا می‌شود و تلاش می‌کند تا یک کار را انجام دهد. هنگامی که کار با تلاش به پایان رسید، در صورت موفقیت‌آمیز بودن، `resolve` یا در صورت وجود هر خطایی `reject` را فراخوانی می‌کند. -The `promise` object returned by the `new Promise` constructor has these internal properties: +شیء `promise` که توسط سازنده `new Promise` برگردانده شده است دارای این ویژگی‌های داخلی است: -- `state` — initially `"pending"`, then changes to either `"fulfilled"` when `resolve` is called or `"rejected"` when `reject` is called. -- `result` — initially `undefined`, then changes to `value` when `resolve(value)` called or `error` when `reject(error)` is called. +- `state` — .تغییر می‌کند `"rejected"` فراخوانی می‌شود به `reject` یا زمانی که `"fulfilled"` به `resolve` سپس با فراخوانی، `"pending"` در ابتدا +- `result` — .تغییر می‌کند `error` فراخوانی می شود به `reject(error)` یا زمانی که `value` به `resolve(value)` سپس با فراخوانی ،`undefined` در ابتدا -So the executor eventually moves `promise` to one of these states: +بنابراین اجرا‌کننده در نهایت `promise` را به یکی از این حالات منتقل می‌کند: ![](promise-resolve-reject.svg) -Later we'll see how "fans" can subscribe to these changes. +بعداً خواهیم دید که چگونه "طرفداران" می‌توانند در این تغییرات مشترک شوند. -Here's an example of a promise constructor and a simple executor function with "producing code" that takes time (via `setTimeout`): +در اینجا یک نمونه از سازنده وعده (promise) و یک تابع اجرا‌کننده ساده با "کد تولید‌کننده" است که زمانی می‌برد (از طریق `setTimeout`): ```js run let promise = new Promise(function(resolve, reject) { From 79ae48f0014fa7772e3f69c7f12d0e05cd961745 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Sun, 23 Jan 2022 14:26:05 +0330 Subject: [PATCH 05/28] calling after ready --- 1-js/11-async/02-promise-basics/article.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index c5f50c001..f3a19d4c4 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -48,17 +48,17 @@ let promise = new Promise(function(resolve, reject) { ```js run let promise = new Promise(function(resolve, reject) { - // the function is executed automatically when the promise is constructed + // ساخته می‌شود به طور خودکار اجرا می‌شود (promise)این تابع زمانی که وعده - // after 1 second signal that the job is done with the result "done" + // انجام شد "done" پس از 1 ثانیه سیگنال می‌دهد که کار با نتیجه setTimeout(() => *!*resolve("done")*/!*, 1000); }); ``` -We can see two things by running the code above: +با اجرای کد بالا می توانیم دو چیز را ببینیم: -1. The executor is called automatically and immediately (by `new Promise`). -2. The executor receives two arguments: `resolve` and `reject`. These functions are pre-defined by the JavaScript engine, so we don't need to create them. We should only call one of them when ready. +۱. اجرا‌کننده به صورت خودکار و بلافاصله فراخوانی می‌شود (توسط `new Promise`).
+۲. اجرا‌کننده دو آرگومان دریافت می‌کند: `resolve` و `reject`. این توابع توسط موتور جاوااسکریپت از پیش تعریف شده‌اند, بنابراین ما نیازی به ایجاد آن‌ها نداریم. وقتی آماده شدیم فقط باید یکی از آن‌ها را فراخوانی کنیم. After one second of "processing" the executor calls `resolve("done")` to produce the result. This changes the state of the `promise` object: From 0b663d6a5b8caa179e4fd7b72647013f7ad087a3 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 25 Jan 2022 20:00:07 +0330 Subject: [PATCH 06/28] resolved --- 1-js/11-async/02-promise-basics/article.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index f3a19d4c4..221470c28 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -60,28 +60,28 @@ let promise = new Promise(function(resolve, reject) { ۱. اجرا‌کننده به صورت خودکار و بلافاصله فراخوانی می‌شود (توسط `new Promise`).
۲. اجرا‌کننده دو آرگومان دریافت می‌کند: `resolve` و `reject`. این توابع توسط موتور جاوااسکریپت از پیش تعریف شده‌اند, بنابراین ما نیازی به ایجاد آن‌ها نداریم. وقتی آماده شدیم فقط باید یکی از آن‌ها را فراخوانی کنیم. - After one second of "processing" the executor calls `resolve("done")` to produce the result. This changes the state of the `promise` object: + :را تغییر می‌دهد `promise` را برای ایجاد نتیجه فراخوانی می‌کند. این وضعیت شیء `resolve("done")` پس از یک ثانیه "پردازش"، اجرا‌کننده ![](promise-resolve-1.svg) -That was an example of a successful job completion, a "fulfilled promise". +این نمونه‌ای از تکمیل موفقیت آمیز کار بود، یک "fulfilled promise". -And now an example of the executor rejecting the promise with an error: +و حال نمونه‌ای از ردشدن(rejecting) وعده‌ی(promise) اجرا‌کننده با یک خطا: ```js let promise = new Promise(function(resolve, reject) { - // after 1 second signal that the job is finished with an error + // بعد از 1 ثانیه سیگنال می‌دهد که کار با یک خطا تمام شده است setTimeout(() => *!*reject(new Error("Whoops!"))*/!*, 1000); }); ``` -The call to `reject(...)` moves the promise object to `"rejected"` state: +فراخوانیِ `(...)reject` شیء وعده(promise) را به وضعیت `"rejected"` می‌برد: ![](promise-reject-1.svg) -To summarize, the executor should perform a job (usually something that takes time) and then call `resolve` or `reject` to change the state of the corresponding promise object. +به طور خلاصه، اجرا‌کننده باید یک کار را انجام دهد (معمولاً کاری که زمان می‌برد) و سپس `resolve` یا `reject` را برای تغییر وضعیت شیء وعده‌ی(promise) مربوطه فراخوانی کند. -A promise that is either resolved or rejected is called "settled", as opposed to an initially "pending" promise. +به وعده‌ای که یا حل‌و‌فصل(resolved) می‌شود یا رد(rejected) می‌شود، "تسویه‌شده" ("settled") می‌گویند، برخلاف وعده‌ای(promise) که در ابتدا "درحال انتظار" ("pending") است. ````smart header="There can be only a single result or an error" The executor should call only one `resolve` or one `reject`. Any state change is final. From fefe0d78aaf34e7bda8ceeb0e1fba87b9785302a Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Sat, 29 Jan 2022 15:43:20 +0330 Subject: [PATCH 07/28] additional arg --- 1-js/11-async/02-promise-basics/article.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index 221470c28..7b1a0d66b 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -83,10 +83,10 @@ let promise = new Promise(function(resolve, reject) { به وعده‌ای که یا حل‌و‌فصل(resolved) می‌شود یا رد(rejected) می‌شود، "تسویه‌شده" ("settled") می‌گویند، برخلاف وعده‌ای(promise) که در ابتدا "درحال انتظار" ("pending") است. -````smart header="There can be only a single result or an error" -The executor should call only one `resolve` or one `reject`. Any state change is final. +````smart header="تنها یک نتیجه یا یک خطا می تواند وجود داشته باشد" +.را فراخوانی کند. هر تغییر وضعیتی نهایی است `reject` یا یک `resolve` اجرا‌کننده باید فقط یک -All further calls of `resolve` and `reject` are ignored: +:نادیده گرفته می‌شوند `reject` و `resolve` همه فراخوانی‌های دیگر از ```js let promise = new Promise(function(resolve, reject) { @@ -94,14 +94,14 @@ let promise = new Promise(function(resolve, reject) { resolve("done"); */!* - reject(new Error("…")); // ignored - setTimeout(() => resolve("…")); // ignored + reject(new Error("…")); // نادیده گرفته شد + setTimeout(() => resolve("…")); // نادیده گرفته شد }); ``` -The idea is that a job done by the executor may have only one result or an error. +ایده این است که کار انجام شده توسط اجرا‌کننده ممکن است تنها یک نتیجه یا یک خطا داشته باشد. -Also, `resolve`/`reject` expect only one argument (or none) and will ignore additional arguments. +.تنها یک آرگومان (یا هیچی) را انتظار دارد و آرگومان‌های اضافی را نادیده می‌گیرد `resolve`/`reject` ،همچنین ```` ```smart header="Reject with `Error` objects" From a140d3b7b96239dd1a93b0e2b4358d0da26e1169 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Mon, 31 Jan 2022 12:57:24 +0330 Subject: [PATCH 08/28] object Error --- 1-js/11-async/02-promise-basics/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index 7b1a0d66b..b6bb680d3 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -104,8 +104,8 @@ let promise = new Promise(function(resolve, reject) { .تنها یک آرگومان (یا هیچی) را انتظار دارد و آرگومان‌های اضافی را نادیده می‌گیرد `resolve`/`reject` ،همچنین ```` -```smart header="Reject with `Error` objects" -In case something goes wrong, the executor should call `reject`. That can be done with any type of argument (just like `resolve`). But it is recommended to use `Error` objects (or objects that inherit from `Error`). The reasoning for that will soon become apparent. +```smart header="کنید (reject)رد `Error` با اشیاء"
+در صورتی که مشکلی پیش بیاید، اجرا‌کننده باید `reject` را فراخوانی کند. این کار می‌تواند با هر نوع آرگومانی انجام شود (دقیقاً مانند `resolve`). اما توصیه می‌شود از اشیاء `Error` (یا اشیایی که از `Error` به ارث می‌برند) استفاده کنید. دلیل آن به زودی مشخص خواهد شد. ``` ````smart header="Immediately calling `resolve`/`reject`" From c84a77ae677c923469464304e885d27361f211eb Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 1 Feb 2022 07:29:11 +0330 Subject: [PATCH 09/28] promise resolved --- 1-js/11-async/02-promise-basics/article.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index b6bb680d3..a86dfcdf5 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -108,19 +108,19 @@ let promise = new Promise(function(resolve, reject) { در صورتی که مشکلی پیش بیاید، اجرا‌کننده باید `reject` را فراخوانی کند. این کار می‌تواند با هر نوع آرگومانی انجام شود (دقیقاً مانند `resolve`). اما توصیه می‌شود از اشیاء `Error` (یا اشیایی که از `Error` به ارث می‌برند) استفاده کنید. دلیل آن به زودی مشخص خواهد شد. ``` -````smart header="Immediately calling `resolve`/`reject`" -In practice, an executor usually does something asynchronously and calls `resolve`/`reject` after some time, but it doesn't have to. We also can call `resolve` or `reject` immediately, like this: +````smart header="را فراخوانی می‌کند `Resolve`/`Reject` بلافاصله" +:را فراخوانی کنیم، مانند این `reject` یا `resolve` را فراخوانی می‌کند، اما مجبور نیست. همچنین می‌توانیم بلافاصله `resolve`/`reject` در عمل، یک اجرا‌کننده معمولاً کاری را به صورت ناهمزمان انجام می‌دهد و پس از مدتی ```js let promise = new Promise(function(resolve, reject) { - // not taking our time to do the job - resolve(123); // immediately give the result: 123 + // وقت خود را برای انجام کار صرف نمی کنیم + resolve(123); // بلافاصله نتیجه را بدهید: 123 }); ``` -For instance, this might happen when we start to do a job but then see that everything has already been completed and cached. +به عنوان مثال، این ممکن است زمانی اتفاق بیفتد که ما شروع به انجام یک کار می‌کنیم، اما بعد می‌بینیم که همه چیز قبلاً تکمیل شده و در حافظه پنهان(cache) ذخیره شده است. -That's fine. We immediately have a resolved promise. +خوبه. ما بلافاصله یک وعده(promise) حل‌شده(resolved) داریم. ```` ```smart header="The `state` and `result` are internal" From 0d89ed22ebaf1e1fe00f1c83a5a2aa3fd64e624d Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Wed, 2 Feb 2022 07:15:36 +0330 Subject: [PATCH 10/28] handle --- 1-js/11-async/02-promise-basics/article.md | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index a86dfcdf5..dc068eca3 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -123,30 +123,30 @@ let promise = new Promise(function(resolve, reject) { خوبه. ما بلافاصله یک وعده(promise) حل‌شده(resolved) داریم. ```` -```smart header="The `state` and `result` are internal" -The properties `state` and `result` of the Promise object are internal. We can't directly access them. We can use the methods `.then`/`.catch`/`.finally` for that. They are described below. -``` +```smart header="داخلی هستند `result` و `state`" +.استفاده کنیم. در زیر توضیح داده شده‌اند `.then`/`.catch`/`.finally` داخلی هستند. ما نمی‌توانیم مستقیماً به آن‌ها دسترسی داشته باشیم. برای این کار می‌توانیم از متدهای Promise شیء `result` و `state` ویژگی های +````` -## Consumers: then, catch, finally +## مصرف‌کنندگان: then, catch, finally -A Promise object serves as a link between the executor (the "producing code" or "singer") and the consuming functions (the "fans"), which will receive the result or error. Consuming functions can be registered (subscribed) using methods `.then`, `.catch` and `.finally`. +یک شیء Promise به عنوان یک پیوند بین اجراکننده ("کد تولید‌کننده" یا "خواننده") و توابع مصرف‌کننده ("طرفداران") عمل می‌کند که نتیجه یا خطا را دریافت می‌کند. توابع مصرف‌کننده را می‌توان با استفاده از متدهای `then`، `.catch.` و `finally.` ثبت (مشترک) کرد. -### then +### متدِ then -The most important, fundamental one is `.then`. +مهم ترین و اساسی ترین آن `then.` است. -The syntax is: +نحو(syntax) عبارت است از: ```js promise.then( - function(result) { *!*/* handle a successful result */*/!* }, - function(error) { *!*/* handle an error */*/!* } + function(result) { *!*/* یک نتیجه موفق را مدیریت کنید */*/!* }, + function(error) { *!*/* یک خطا را مدیریت کنید */*/!* } ); ``` -The first argument of `.then` is a function that runs when the promise is resolved, and receives the result. +اولین آرگومان `then.` تابعی است که با حل شدن(resolved) وعده(promise) اجرا می‌شود و نتیجه را دریافت می‌کند. -The second argument of `.then` is a function that runs when the promise is rejected, and receives the error. +آرگومان دوم `then.` تابعی است که با رد شدن(rejected) وعده(promise) اجرا می‌شود و خطا را دریافت می‌کند. For instance, here's a reaction to a successfully resolved promise: From 161c6d9a57550121fd640452bbf541e7c9c3c4aa Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Wed, 2 Feb 2022 07:29:42 +0330 Subject: [PATCH 11/28] runs first function --- 1-js/11-async/02-promise-basics/article.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index dc068eca3..d1616bcbf 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -14,7 +14,7 @@ این تشبیه خیلی دقیق نیست، زیرا وعده‌های (promises) جاوا‌اسکریپت پیچیده‌تر از یک لیست اشتراک ساده است: آن‌ها دارای ویژگی‌ها و محدودیت‌های اضافی هستند. اما برای شروع خوب است. -نحوِ (syntax) سازنده برای یک شیء وعده (promise) به صورت زیر است: +سینتکس سازنده برای یک شیء وعده(promise) به صورت زیر است: ```js let promise = new Promise(function(resolve, reject) { @@ -125,7 +125,7 @@ let promise = new Promise(function(resolve, reject) { ```smart header="داخلی هستند `result` و `state`" .استفاده کنیم. در زیر توضیح داده شده‌اند `.then`/`.catch`/`.finally` داخلی هستند. ما نمی‌توانیم مستقیماً به آن‌ها دسترسی داشته باشیم. برای این کار می‌توانیم از متدهای Promise شیء `result` و `state` ویژگی های -````` +``` ## مصرف‌کنندگان: then, catch, finally @@ -135,7 +135,7 @@ let promise = new Promise(function(resolve, reject) { مهم ترین و اساسی ترین آن `then.` است. -نحو(syntax) عبارت است از: +سینتکس عبارت است از: ```js promise.then( @@ -148,14 +148,14 @@ promise.then( آرگومان دوم `then.` تابعی است که با رد شدن(rejected) وعده(promise) اجرا می‌شود و خطا را دریافت می‌کند. -For instance, here's a reaction to a successfully resolved promise: +به عنوان مثال، در اینجا یک واکنش به یک وعده‌ی(promise) با موفقیت حل شده(resolved) داریم: ```js run let promise = new Promise(function(resolve, reject) { setTimeout(() => resolve("done!"), 1000); }); -// resolve runs the first function in .then +// اجرا می کند resolve را .then اولین تابع در promise.then( *!* result => alert(result), // shows "done!" after 1 second From 0fae38d3051eb144e0de044e35c25453419721e6 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Mon, 7 Feb 2022 06:50:19 +0330 Subject: [PATCH 12/28] catch method --- 1-js/11-async/02-promise-basics/article.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index d1616bcbf..a05611b3a 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -125,7 +125,7 @@ let promise = new Promise(function(resolve, reject) { ```smart header="داخلی هستند `result` و `state`" .استفاده کنیم. در زیر توضیح داده شده‌اند `.then`/`.catch`/`.finally` داخلی هستند. ما نمی‌توانیم مستقیماً به آن‌ها دسترسی داشته باشیم. برای این کار می‌توانیم از متدهای Promise شیء `result` و `state` ویژگی های -``` +````` ## مصرف‌کنندگان: then, catch, finally @@ -158,31 +158,31 @@ let promise = new Promise(function(resolve, reject) { // اجرا می کند resolve را .then اولین تابع در promise.then( *!* - result => alert(result), // shows "done!" after 1 second + result => alert(result), // نشان می‌دهد "Done!" بعد از 1 ثانیه */!* - error => alert(error) // doesn't run + error => alert(error) // اجرا نمی‌شود ); ``` -The first function was executed. +اولین تابع اجرا شد. -And in the case of a rejection, the second one: +و در صورت ردشدن دومی: ```js run let promise = new Promise(function(resolve, reject) { setTimeout(() => reject(new Error("Whoops!")), 1000); }); -// reject runs the second function in .then +// اجرا می کند .then تابع دوم را در reject promise.then( - result => alert(result), // doesn't run + result => alert(result), // اجرا نمی‌شود *!* - error => alert(error) // shows "Error: Whoops!" after 1 second + error => alert(error) // نشان می‌دهد "Error: Whoops!" بعد از 1 ثانیه */!* ); ``` -If we're interested only in successful completions, then we can provide only one function argument to `.then`: +اگر فقط به تکمیل موفقیت‌آمیز علاقه داریم، می‌توانیم تنها یک آرگومان تابع را برای `then.` ارائه کنیم: ```js run let promise = new Promise(resolve => { @@ -190,11 +190,11 @@ let promise = new Promise(resolve => { }); *!* -promise.then(alert); // shows "done!" after 1 second +promise.then(alert); // نشان می‌دهد "done!" بعد از 1 ثانیه */!* ``` -### catch +### متدِ catch 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: From 8ce413e5218c528ddc1e173655b402b331ee6624 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Sat, 12 Feb 2022 07:30:59 +0330 Subject: [PATCH 13/28] finally method --- 1-js/11-async/02-promise-basics/article.md | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index a05611b3a..071fd151c 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -196,7 +196,7 @@ promise.then(alert); // نشان می‌دهد "done!" بعد از 1 ثانیه ### متدِ catch -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: +اگر فقط به خطاها علاقه‌مند هستیم، می‌توانیم از `null` به عنوان اولین آرگومان استفاده کنیم: `then(null، errorHandlingFunction).`. یا می‌توانیم از `catch(errorHandlingFunction).` استفاده کنیم که دقیقاً مشابه است: ```js run @@ -206,32 +206,32 @@ let promise = new Promise((resolve, reject) => { *!* // .catch(f) is the same as promise.then(null, f) -promise.catch(alert); // shows "Error: Whoops!" after 1 second +promise.catch(alert); // .را بعد از 1 ثانیه نشان می‌دهد "Error: Whoops!" خطای */!* ``` -The call `.catch(f)` is a complete analog of `.then(null, f)`, it's just a shorthand. +فراخوانی `catch(f).` یک تشابه کامل از `then(null, f).` است. این فقط یک کوتاه نویسی است. -### finally +### متدِ finally -Just like there's a `finally` clause in a regular `try {...} catch {...}`, there's `finally` in promises. +درست مانند یک بند `finally` در یک `catch {...} try {...}` معمولی، در وعده‌ها(promises) نیز `finally` وجود دارد. -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. +فراخوانی `finally(f).` شبیه به `then(f, f).` است به این معنا که `f` همیشه زمانی که وعده(promise) تسویه(settled) می‌شود اجرا می‌شود: خواه حل‌وفصل(resolve) یا رد(reject) شود. -`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. +متدِ `finally` یک کنترل‌کننده خوب برای انجام پاکسازی است، به عنوان مثال. نشانگرهای بارگیری(loading indicators) خود را متوقف می‌کنیم، زیرا بدون توجه به نتیجه، دیگر به آن‌ها نیازی نیست. -Like this: +مثل این: ```js new Promise((resolve, reject) => { - /* do something that takes time, and then call resolve/reject */ + /* را فراخوانی کنید resolve/reject کاری را انجام دهید که زمان می‌برد و سپس */ }) *!* - // runs when the promise is settled, doesn't matter successfully or not - .finally(() => stop loading indicator) - // so the loading indicator is always stopped before we process the result/error + // زمانی اجرا می‌شود که وعده تسویه شود، مهم نیست موفقیت‌آمیز باشد یا نه + .finally(() => توقف نشانه‌گر بارگیری) + // بنابراین نشانگر بارگیری همیشه قبل از پردازش نتیجه/خطا متوقف می‌شود */!* - .then(result => show result, err => show error) + .then(result => نمایش نتیجه, err => نمایش خطا) ``` That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are few subtle differences: From 4cf1b49b2c4ae01450bb6563a337b74f8640990f Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Sun, 13 Feb 2022 07:06:46 +0330 Subject: [PATCH 14/28] finally pass --- 1-js/11-async/02-promise-basics/article.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index 071fd151c..9512b3991 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -234,12 +234,12 @@ new Promise((resolve, reject) => { .then(result => نمایش نتیجه, err => نمایش خطا) ``` -That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are few subtle differences: +با این حال، `finally(f)` دقیقاً نام مستعار `then(f,f)` نیست. چند تفاوت ظریف وجود دارد: -1. A `finally` handler has no arguments. In `finally` we don't know whether the promise is successful or not. That's all right, as our task is usually to perform "general" finalizing procedures. -2. A `finally` handler passes through results and errors to the next handler. +۱. یک کنترل‌کننده `finally` هیچ آرگومانی ندارد. در `finally` ما نمی‌دانیم که آیا وعده(promise) موفق است یا نه. همه چیز درست است، زیرا وظیفه ما معمولاً انجام مراحل نهایی‌سازی "عمومی" است. +۲. یک کنترل‌کننده `finally` نتایج و خطاها را به کنترل‌کننده بعدی منتقل می‌کند. - For instance, here the result is passed through `finally` to `then`: + :منتقل می‌شود `then` به `finally` به عنوان مثال، در اینجا نتیجه از ```js run new Promise((resolve, reject) => { setTimeout(() => resolve("result"), 2000) From b5488862272c816f28b77dd319be195d6d263d2a Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 08:18:32 +0330 Subject: [PATCH 15/28] let's --- 1-js/11-async/02-promise-basics/article.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index 9512b3991..db134f432 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -245,10 +245,10 @@ new Promise((resolve, reject) => { setTimeout(() => resolve("result"), 2000) }) .finally(() => alert("Promise ready")) - .then(result => alert(result)); // <-- .then handles the result + .then(result => alert(result)); // <-- نتیجه را اجرا می‌کند .then ``` - And here there's an error in the promise, passed through `finally` to `catch`: + :پاس داده می‌شود `catch` به `finally` و در اینجا یک خطایی در وعده وجود دارد که از ```js run new Promise((resolve, reject) => { @@ -258,27 +258,27 @@ new Promise((resolve, reject) => { .catch(err => alert(err)); // <-- .catch handles the error object ``` -That's very convenient, because `finally` is not meant to process a promise result. So it passes it through. +این بسیار راحت است، زیرا `finally` به معنای پردازش یک نتیجه وعده(promise) نیست. بنابراین از آن عبور می‌کند. -We'll talk more about promise chaining and result-passing between handlers in the next chapter. +در فصل بعدی بیشتر در مورد زنجیره وعده(promise) و انتقال نتیجه بین اجراکنندگان صحبت خواهیم کرد. -````smart header="We can attach handlers to settled promises" -If a promise is pending, `.then/catch/finally` handlers wait for it. Otherwise, if a promise has already settled, they just run: +````smart header="ما می توانیم اجراکننده‌ها را به وعده‌های تسویه‌شده متصل کنیم" +اگر وعده‌ای در حال تعلیق است، اجراکنندگان `then/catch/finally.` منتظر آن هستند. در غیر این صورت، اگر وعده‌ای قبلاً تسویه شده باشد، آنها فقط اجرا می کنند: ```js run -// the promise becomes resolved immediately upon creation +// وعده بلافاصله پس از ایجاد حل‌وفصل می‌شود let promise = new Promise(resolve => resolve("done!")); -promise.then(alert); // done! (shows up right now) +promise.then(alert); // done! (همین الآن نشان می‌دهد) ``` -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. +توجه داشته باشید که این باعث می‌شود وعده‌ها قدرتمندتر از سناریوی واقعی "فهرست اشتراک" باشد. اگر خواننده قبلا آهنگ خود را منتشر کرده باشد و سپس شخصی در لیست اشتراک ثبت نام کند، احتمالاً آن آهنگ را دریافت نخواهد کرد. اشتراک در دنیای واقعی باید قبل از رویداد انجام شود. -Promises are more flexible. We can add handlers any time: if the result is already there, they just execute. +وعده‌ها انعطاف‌پذیرتر هستند. ما می توانیم هر زمان که بخواهیم اجراکنندگان را اضافه کنیم: اگر نتیجه از قبل وجود داشته باشد، آنها فقط اجرا می‌شوند. ```` -Next, let's see more practical examples of how promises can help us write asynchronous code. +در مرحله بعد، بیایید نمونه‌های عملی بیشتری را ببینیم که چگونه وعده‌ها می‌توانند به ما در نوشتن کد ناهمزمان کمک کنند. ## Example: loadScript [#loadscript] From c0b9e9acd667461bf929d61cbe3006fa6029d997 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:36:10 +0330 Subject: [PATCH 16/28] table --- 1-js/11-async/02-promise-basics/article.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/1-js/11-async/02-promise-basics/article.md b/1-js/11-async/02-promise-basics/article.md index db134f432..7fcadc4f1 100644 --- a/1-js/11-async/02-promise-basics/article.md +++ b/1-js/11-async/02-promise-basics/article.md @@ -280,11 +280,11 @@ promise.then(alert); // done! (همین الآن نشان می‌دهد) در مرحله بعد، بیایید نمونه‌های عملی بیشتری را ببینیم که چگونه وعده‌ها می‌توانند به ما در نوشتن کد ناهمزمان کمک کنند. -## Example: loadScript [#loadscript] +## مثال: loadScript [#loadscript] -We've got the `loadScript` function for loading a script from the previous chapter. +ما تابع `loadScript` را برای بارگیری یک اسکریپت از فصل قبل داریم. -Here's the callback-based variant, just to remind us of it: +در اینجا یک نوع مبتنی بر کال‌بک(callback) است، فقط برای یادآوری آن: ```js function loadScript(src, callback) { @@ -298,9 +298,9 @@ function loadScript(src, callback) { } ``` -Let's rewrite it using Promises. +بیایید آن را با استفاده از Promises بازنویسی کنیم. -The new function `loadScript` will not require a callback. Instead, it will create and return a Promise object that resolves when the loading is complete. The outer code can add handlers (subscribing functions) to it using `.then`: +تابع جدید `loadScript` نیازی به کال‌بک نخواهد داشت. درعوض، یک شی Promise ایجاد و برمی‌گرداند که پس از اتمام بارگیری حل‌وفصل می‌شود. کد بیرونی می‌تواند با استفاده از `then.`، اجراکنندگان (توابع اشتراک) را به آن اضافه کند: ```js run function loadScript(src) { @@ -329,12 +329,12 @@ promise.then( promise.then(script => alert('Another handler...')); ``` -We can immediately see a few benefits over the callback-based pattern: +ما می‌توانیم بلافاصله چند مزیت را نسبت به الگوی مبتنی بر کال‌بک(callback) مشاهده کنیم: | Promises | Callbacks | |----------|-----------| -| Promises allow us to do things in the natural order. First, we run `loadScript(script)`, and `.then` we write what to do with the result. | We must have a `callback` function at our disposal when calling `loadScript(script, callback)`. In other words, we must know what to do with the result *before* `loadScript` is called. | -| We can call `.then` on a Promise as many times as we want. Each time, we're adding a new "fan", a new subscribing function, to the "subscription list". More about this in the next chapter: [](info:promise-chaining). | There can be only one callback. | +| وعده‌ها به ما این امکان را می‌دهند که کارها را به ترتیب طبیعی انجام دهیم. ابتدا `(loadScript(script` را اجرا می‌کنیم و `.then` می‌نویسیم که با نتیجه چه کنیم. | هنگام فراخوانی `loadScript(script, callback)` باید یک تابع `callback` در اختیار داشته باشیم. به عبارت دیگر، *قبل* از فراخوانی `loadScript` باید بدانیم که با نتیجه چه کنیم. | +| می‌توانیم `.then` را در یک Promise هر چند بار که بخواهیم فراخوانی کنیم. هر بار، یک `طرفدار` جدید، یک تابع اشتراک جدید، به "لیست اشتراک" اضافه می‌کنیم. اطلاعات بیشتر در مورد این در فصل بعدی: [](info:promise-chaining). | فقط یک کال‌بک می‌تواند وجود داشته باشد. | -So promises give us better code flow and flexibility. But there's more. We'll see that in the next chapters. +بنابراین وعده‌ها جریان کد و انعطاف‌پذیری بهتری به ما می‌دهند. اما موارد بیشتری وجود دارد. آن را در فصل‌های بعدی خواهیم دید. From 41ae6fc9efef3e477507596cfd44bbdc1a0458bc Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:39:58 +0330 Subject: [PATCH 17/28] re resolve solution --- 1-js/11-async/02-promise-basics/01-re-resolve/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/11-async/02-promise-basics/01-re-resolve/solution.md b/1-js/11-async/02-promise-basics/01-re-resolve/solution.md index 57046a257..63815b163 100644 --- a/1-js/11-async/02-promise-basics/01-re-resolve/solution.md +++ b/1-js/11-async/02-promise-basics/01-re-resolve/solution.md @@ -1,3 +1,3 @@ -The output is: `1`. +خروجی هست: `1`. -The second call to `resolve` is ignored, because only the first call of `reject/resolve` is taken into account. Further calls are ignored. +فراخوان دوم برای `resolve` نادیده گرفته می‌شود، زیرا فقط اولین فراخوان `reject/resolve` در نظر گرفته می‌شود. فراخوان‌های بیشتر نادیده گرفته می‌شوند. From b3feeb0966fa974201dca6136da0c0376a5d786a Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:41:58 +0330 Subject: [PATCH 18/28] re resolve task --- 1-js/11-async/02-promise-basics/01-re-resolve/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/11-async/02-promise-basics/01-re-resolve/task.md b/1-js/11-async/02-promise-basics/01-re-resolve/task.md index 185806ed6..724a181d1 100644 --- a/1-js/11-async/02-promise-basics/01-re-resolve/task.md +++ b/1-js/11-async/02-promise-basics/01-re-resolve/task.md @@ -1,8 +1,8 @@ -# Re-resolve a promise? +# آیا Re-resolve یک وعده(promise) است؟ -What's the output of the code below? +خروجی کد زیر چیست؟ ```js let promise = new Promise(function(resolve, reject) { From 8582f9dbf3f0a9427b4620e2c8b91f12fa26c837 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:45:35 +0330 Subject: [PATCH 19/28] delay promise solution --- 1-js/11-async/02-promise-basics/02-delay-promise/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/11-async/02-promise-basics/02-delay-promise/solution.md b/1-js/11-async/02-promise-basics/02-delay-promise/solution.md index 85e8baa44..1c09a8e30 100644 --- a/1-js/11-async/02-promise-basics/02-delay-promise/solution.md +++ b/1-js/11-async/02-promise-basics/02-delay-promise/solution.md @@ -3,7 +3,7 @@ function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } -delay(3000).then(() => alert('runs after 3 seconds')); +delay(3000).then(() => alert('بعد از 3 ثانیه اجرا می‌شود')); ``` -Please note that in this task `resolve` is called without arguments. We don't return any value from `delay`, just ensure the delay. +لطفاً توجه داشته باشید که در این کار `resolve` بدون آرگومان فراخوانی می‌شود. ما هیچ مقداری را از `delay` بر نمی‌گردانیم، فقط از تاخیر اطمینان حاصل کنید. From d92e9ee4a1712221f6f14f4f2a0a52ef92bf82c5 Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:54:57 +0330 Subject: [PATCH 20/28] delay promise task --- .../02-promise-basics/02-delay-promise/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/11-async/02-promise-basics/02-delay-promise/task.md b/1-js/11-async/02-promise-basics/02-delay-promise/task.md index 0d74cf45d..453803ea6 100644 --- a/1-js/11-async/02-promise-basics/02-delay-promise/task.md +++ b/1-js/11-async/02-promise-basics/02-delay-promise/task.md @@ -1,14 +1,14 @@ -# Delay with a promise +# تاخیر با وعده(promise) -The built-in function `setTimeout` uses callbacks. Create a promise-based alternative. +تابع داخلی `setTimeout` از کال‌بک‌ها استفاده می‌کند. یک جایگزین مبتنی بر وعده(promise) ایجاد کنید. -The function `delay(ms)` should return a promise. That promise should resolve after `ms` milliseconds, so that we can add `.then` to it, like this: +تابع `delay(ms)` باید یک وعده برگرداند. این وعده باید پس از `ms` میلی‌ثانیه حل‌وفصل شود، به طوری که می‌توانیم `then.` را به آن اضافه کنیم، مانند این: ```js function delay(ms) { - // your code + // کد شما } -delay(3000).then(() => alert('runs after 3 seconds')); +delay(3000).then(() => alert('بعد از 3 ثانیه اجرا می‌شود')); ``` From 3e223e9d3a85ddde9b5f5e2ba5af6e3a7e164e5c Mon Sep 17 00:00:00 2001 From: Behourz <47471154+Beroozam@users.noreply.github.com> Date: Tue, 15 Feb 2022 19:57:39 +0330 Subject: [PATCH 21/28] animate circle promise .html --- .../03-animate-circle-promise/solution.view/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/11-async/02-promise-basics/03-animate-circle-promise/solution.view/index.html b/1-js/11-async/02-promise-basics/03-animate-circle-promise/solution.view/index.html index 6052f009e..9a3c0b67e 100644 --- a/1-js/11-async/02-promise-basics/03-animate-circle-promise/solution.view/index.html +++ b/1-js/11-async/02-promise-basics/03-animate-circle-promise/solution.view/index.html @@ -22,14 +22,14 @@ - +