Skip to content

Promise #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 1-js/11-async/02-promise-basics/01-re-resolve/solution.md
Original file line number Diff line number Diff line change
@@ -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` در نظر گرفته می‌شود. فراخوانی‌های بعدی نادیده گرفته می‌شوند.
4 changes: 2 additions & 2 deletions 1-js/11-async/02-promise-basics/01-re-resolve/task.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Re-resolve a promise?
# آیا یک Promise دوباره resolve می‌شود؟


What's the output of the code below?
خروجی کد زیر چیست؟

```js
let promise = new Promise(function(resolve, reject) {
Expand Down
4 changes: 2 additions & 2 deletions 1-js/11-async/02-promise-basics/02-delay-promise/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` بر نمی‌گردانیم، فقط از تاخیر اطمینان حاصل می‌کنیم.
10 changes: 5 additions & 5 deletions 1-js/11-async/02-promise-basics/02-delay-promise/task.md
Original file line number Diff line number Diff line change
@@ -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)` باید یک Promise برگرداند. این وعده باید پس از `ms` میلی‌ثانیه حل‌وفصل (resolve) شود، به طوری که می‌توانیم `then.` را به آن اضافه کنیم، مانند این:

```js
function delay(ms) {
// your code
// کد شما
}

delay(3000).then(() => alert('runs after 3 seconds'));
delay(3000).then(() => alert('بعد از 3 ثانیه اجرا می‌شود'));
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

<body>

<button onclick="go()">Click me</button>
<button onclick="go()">روی من کلیک کن</button>

<script>

function go() {
showCircle(150, 150, 100).then(div => {
div.classList.add('message-ball');
div.append("Hello, world!");
div.append("سلام دنیا!");
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

# Animated circle with promise
# دایره متحرک با Promise

Rewrite the `showCircle` function in the solution of the task <info:task/animate-circle-callback> so that it returns a promise instead of accepting a callback.
تابع `showCircle` را در راه‌حل تمرین <info:task/animate-circle-callback> بازنویسی کنید تا به جای پذیرش کال‌بک، یک Promise را برگرداند.

The new usage:
کاربرد جدید:

```js
showCircle(150, 150, 100).then(div => {
div.classList.add('message-ball');
div.append("Hello, world!");
div.append("سلام دنیا!");
});
```

Take the solution of the task <info:task/animate-circle-callback> as the base.
راه‌حل تمرین <info:task/animate-circle-callback> را به عنوان پایه در نظر بگیرید.
Loading