From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Incorporating setInterval - Node.js Tutorial
From the course: Node.js Essential Training
Incorporating setInterval
- [Instructor] So let's include another type of timer in this same file. The way I'll do that is by creating a new value called interval. Here we're going to define a certain interval where we want to call a function. So it's going to be every half a second, and we'll also set a current time of zero. From here, we're going to create another function called increment time, and increment time is going to be responsible, every 500 milliseconds, for adding a new 500 milliseconds to the current time. So this will continue to accumulate half-a-seconds, kind of like a really fast clock, a clock that ticks every half a second. So we'll say, waitInterval, then we will console-log, "waiting," currentTime, divided by 1,000 seconds. Excellent, so from here, instead of using setTimeout, which is going to time out and call a function after a certain time, we're going to say setInterval. We'll pass in increment time and our…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Inspecting the global object3m 46s
-
(Locked)
Using the require function3m 4s
-
(Locked)
Handling argument variables with process.argv3m 29s
-
(Locked)
Working with standard input3m 37s
-
(Locked)
Using standard output3m 13s
-
(Locked)
Creating a delay with setTimeout2m 3s
-
(Locked)
Incorporating setInterval2m 51s
-
(Locked)
Reporting progress with setInterval1m 43s
-
-
-
-