Skip to content

Promise #150

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
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`.
Rezultatul este: `1`.

The second call to `resolve` is ignored, because only the first call of `reject/resolve` is taken into account. Further calls are ignored.
Al doilea apel la `resolve` este ignorat, deoarece doar primul apel la `reject/resolve` este luat în considerare. Apelurile ulterioare sunt ignorate.
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?
# Re-rezolvați o promisiune?


What's the output of the code below?
Care este rezultatul codului de mai jos?

```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('rulează după 3 secunde'));
```

Please note that in this task `resolve` is called without arguments. We don't return any value from `delay`, just ensure the delay.
Vă rugăm să rețineți că în această sarcină `resolve` este apelat fără argumente. Nu returnăm nicio valoare din `delay`, ci doar asigurăm întârzierea.
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
# Întârzie cu o promisiune

The built-in function `setTimeout` uses callbacks. Create a promise-based alternative.
Funcția încorporată `setTimeout` utilizează callback-uri. Creați o alternativă bazată pe promisiuni.

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:
Funcția `delay(ms)` ar trebui să returneze o promisiune. Această promisiune ar trebui să se rezolve după `ms` milisecunde, astfel încât să putem adăuga `.then` la ea, astfel:

```js
function delay(ms) {
// your code
// codul tău
}

delay(3000).then(() => alert('runs after 3 seconds'));
delay(3000).then(() => alert('rulează după 3 secunde'));
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

# Animated circle with promise
# Cerc animat cu promisiune

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.
Rescrieți funcția `showCircle` din soluția sarcinii <info:task/animate-circle-callback> astfel încât să returneze o promisiune în loc să accepte un callback.

The new usage:
Noua utilizare:

```js
showCircle(150, 150, 100).then(div => {
Expand All @@ -12,4 +12,4 @@ showCircle(150, 150, 100).then(div => {
});
```

Take the solution of the task <info:task/animate-circle-callback> as the base.
Luați ca bază soluția task-ului <info:task/animate-circle-callback>.
290 changes: 145 additions & 145 deletions 1-js/11-async/02-promise-basics/article.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 1-js/11-async/02-promise-basics/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
script.src = src;

script.onload = () => resolve(script);
script.onerror = () => reject(new Error("Script load error: " + src));
script.onerror = () => reject(new Error("Eroare de încărcare a scriptului: " + src));

document.head.append(script);
});
Expand Down