You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/08-settimeout-setinterval/1-output-numbers-100ms/solution.md
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -38,5 +38,27 @@ function printNumbers(from, to) {
38
38
printNumbers(5, 10);
39
39
```
40
40
41
-
Note that in both solutions, there is an initial delay before the first output. Sometimes we need to add a line to make the first output immediately, that's easy to do.
41
+
Note that in both solutions, there is an initial delay before the first output. The function is called after `1000ms`the first time.
42
42
43
+
If we also want the function to run immediately, then we can add an additional call on a separate line, like this:
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/08-settimeout-setinterval/article.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -176,7 +176,7 @@ let timerId = setTimeout(function request() {
176
176
```
177
177
178
178
179
-
And if we regularly have CPU-hungry tasks, then we can measure the time taken by the execution and plan the next call sooner or later.
179
+
And if we 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.
180
180
181
181
**Recursive `setTimeout` guarantees a delay between the executions, `setInterval` -- does not.**
182
182
@@ -354,7 +354,7 @@ function count() {
354
354
count();
355
355
```
356
356
357
-
Now when we start to `count()` and know that we'll need to `count()` more, we schedule that immediately, before doing the job.
357
+
Now when we start to `count()` and see that we'll need to `count()` more, we schedule that immediately, before doing the job.
358
358
359
359
If you run it, it's easy to notice that it takes significantly less time.
0 commit comments