addkmfk.blogg.se

Node js sleep function
Node js sleep function







Your code may look something like this: const alert = "We are ready start the movie" Add a timer with the delay set to the length of the pre-show. In this file define the variable alert that will tell the movie attendant to start the movie when the pre-show waiting period is up. You are excited, but you're stuck watching the pre-show as the movie attendant is waiting for the cue to run the movie. Imagine that you are at the movie theatre, and are about to watch a movie. delay: The number of milliseconds to delay before calling callbackĪny additional arguments will be passed to the callback function when it executes.callback: The callback function that needs to be called when the delay time is up.

node js sleep function

The setTimeout() function takes two main arguments:

node js sleep function

SetTimeout() is a one-time timer that allows us to schedule code to be run after a certain period of time.Įxample: setTimeout(function, delay,,. Scheduling a one time callback with setTimeout() Learn how to use setTimeout() and setInterval() in your code and observe execution of their callbacks during the Event Loop execution.









Node js sleep function