Skip to content

Commit aa4334b

Browse files
committed
translated until 235
1 parent f3128b3 commit aa4334b

File tree

1 file changed

+21
-21
lines changed
  • 1-js/06-advanced-functions/08-settimeout-setinterval

1 file changed

+21
-21
lines changed

1-js/06-advanced-functions/08-settimeout-setinterval/article.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ Metoda imbricată `setTimeout` este mai flexibilă decât `setInterval`. În ace
157157

158158
De exemplu, trebuie să scriem un serviciu care să trimită o solicitare către server la fiecare 5 secunde pentru a cere date, dar în cazul în care serverul este supraîncărcat, ar trebui să crească intervalul la 10, 20, 40 de secunde...
159159

160-
Here's the pseudocode:
160+
Iată pseudocodul:
161161
```js
162162
let delay = 5000;
163163

164164
let timerId = setTimeout(function request() {
165165
...send request...
166166

167167
if (request failed due to server overload) {
168-
// increase the interval to the next run
168+
// crește intervalul până la următoarea execuție
169169
delay *= 2;
170170
}
171171

@@ -175,11 +175,11 @@ let timerId = setTimeout(function request() {
175175
```
176176

177177

178-
And if the functions that we're scheduling are CPU-hungry, then we can measure the time taken by the execution and plan the next call sooner or later.
178+
Iar dacă funcțiile pe care le planificăm sunt mari consumatoare de CPU, atunci putem măsura timpul de execuție și putem planifica următorul apel mai devreme sau mai târziu.
179179

180-
**Nested `setTimeout` allows to set the delay between the executions more precisely than `setInterval`.**
180+
**`setTimeout`-ul imbricat permite stabilirea întârzierii dintre execuții mai precis decât `setInterval`.**
181181

182-
Let's compare two code fragments. The first one uses `setInterval`:
182+
Să comparăm două fragmente de cod. Primul utilizează `setInterval`:
183183

184184
```js
185185
let i = 1;
@@ -188,7 +188,7 @@ setInterval(function() {
188188
}, 100);
189189
```
190190

191-
The second one uses nested `setTimeout`:
191+
Al doilea utilizează `setTimeout` imbricat:
192192

193193
```js
194194
let i = 1;
@@ -198,41 +198,41 @@ setTimeout(function run() {
198198
}, 100);
199199
```
200200

201-
For `setInterval` the internal scheduler will run `func(i++)` every 100ms:
201+
Pentru `setInterval` planificatorul intern va rula `func(i++)` la fiecare 100 ms:
202202

203203
![](setinterval-interval.svg)
204204

205-
Did you notice?
205+
Ați observat?
206206

207-
**The real delay between `func` calls for `setInterval` is less than in the code!**
207+
**Întârzierea reală între apelurile `func` pentru `setInterval` este mai mică decât în cod!**
208208

209-
That's normal, because the time taken by `func`'s execution "consumes" a part of the interval.
209+
Este normal, pentru că timpul ocupat de execuția lui `func` "consumă" o parte din interval.
210210

211-
It is possible that `func`'s execution turns out to be longer than we expected and takes more than 100ms.
211+
Este posibil ca execuția lui `func` să se dovedească a fi mai lungă decât ne așteptam și să dureze mai mult de 100ms.
212212

213-
In this case the engine waits for `func` to complete, then checks the scheduler and if the time is up, runs it again *immediately*.
213+
În acest caz motorul așteaptă ca `func` să se termine, apoi verifică planificatorul și dacă timpul a expirat, îl rulează din nou *imediat*.
214214

215-
In the edge case, if the function always executes longer than `delay` ms, then the calls will happen without a pause at all.
215+
În cazul marginal, dacă funcția se execută întotdeauna mai îndelungat decât `delay` ms, atunci apelurile se vor întâmpla fără nicio pauză.
216216

217-
And here is the picture for the nested `setTimeout`:
217+
Și iată imaginea pentru `setTimeout` imbricat:
218218

219219
![](settimeout-interval.svg)
220220

221-
**The nested `setTimeout` guarantees the fixed delay (here 100ms).**
221+
**`setTimeout`-ul imbricat garantează întârzierea fixă (aici 100ms).**
222222

223-
That's because a new call is planned at the end of the previous one.
223+
Asta pentru că un nou apel este planificat la sfârșitul celui precedent.
224224

225-
````smart header="Garbage collection and setInterval/setTimeout callback"
226-
When a function is passed in `setInterval/setTimeout`, an internal reference is created to it and saved in the scheduler. It prevents the function from being garbage collected, even if there are no other references to it.
225+
````smart header="Colectarea gunoiului și callback-ul setInterval/setTimeout"
226+
Atunci când o funcție este predată în `setInterval/setTimeout`, este creată o referință internă la aceasta și salvată în planificator. Aceasta previne ca funcția să fie colectată la gunoi, chiar dacă nu există alte referințe la ea.
227227
228228
```js
229-
// the function stays in memory until the scheduler calls it
229+
// funcția rămâne în memorie până când planificatorul o apelează
230230
setTimeout(function() {...}, 100);
231231
```
232232
233-
For `setInterval` the function stays in memory until `clearInterval` is called.
233+
Pentru `setInterval`, funcția rămâne în memorie până când este apelată `clearInterval`.
234234
235-
There's a side effect. A function references the outer lexical environment, so, while it lives, outer variables live too. They may take much more memory than the function itself. So when we don't need the scheduled function anymore, it's better to cancel it, even if it's very small.
235+
Există un efect secundar. O funcție face referire la mediul lexical extern, astfel încât, în timp ce ea trăiește, trăiesc și variabilele externe. Acestea pot ocupa mult mai multă memorie decât funcția însăși. Deci atunci când nu mai avem nevoie de funcția programată, este mai bine să o anulăm, chiar dacă este foarte mică.
236236
````
237237

238238
## Zero delay setTimeout

0 commit comments

Comments
 (0)