◐ Shell
clean mode source ↗

Promise by Beroozam · Pull Request #197 · javascript-tutorial/fa.javascript.info

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

Promise #197

Changes from all commits

Commits

Show all changes

28 commits

Select commit Hold shift + click to select a range

5daaa74

promise

Beroozam Jan 16, 2022

a42e936

syntax

Beroozam Jan 17, 2022

f18594f

resolve and reject

Beroozam Jan 19, 2022

db7e505

takes time

Beroozam Jan 21, 2022

79ae48f

calling after ready

Beroozam Jan 23, 2022

0b663d6

resolved

Beroozam Jan 25, 2022

fefe0d7

additional arg

Beroozam Jan 29, 2022

a140d3b

object Error

Beroozam Jan 31, 2022

c84a77a

promise resolved

Beroozam Feb 1, 2022

0d89ed2

handle

Beroozam Feb 2, 2022

161c6d9

runs first function

Beroozam Feb 2, 2022

0fae38d

catch method

Beroozam Feb 7, 2022

8ce413e

finally method

Beroozam Feb 12, 2022

4cf1b49

finally pass

Beroozam Feb 13, 2022

b548886

let's

Beroozam Feb 15, 2022

c0b9e9a

table

Beroozam Feb 15, 2022

41ae6fc

re resolve solution

Beroozam Feb 15, 2022

b3feeb0

re resolve task

Beroozam Feb 15, 2022

8582f9d

delay promise solution

Beroozam Feb 15, 2022

d92e9ee

delay promise task

Beroozam Feb 15, 2022

3e223e9

animate circle promise .html

Beroozam Feb 15, 2022

8bbdb2f

animate circle promise task

Beroozam Feb 15, 2022

8c021fa

delay promise solution2

Beroozam Feb 15, 2022

d40914b

review

Beroozam Feb 16, 2022

ce43fa3

review2

Beroozam Feb 16, 2022

2d1288a

Apply suggestions from code review

Beroozam Feb 16, 2022

3c76446

Apply suggestions from code review

Beroozam Mar 1, 2022

9763d18

Apply suggestions from code review

Beroozam Mar 2, 2022

File filter

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
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> را به عنوان پایه در نظر بگیرید.