Still, the noticeable drawback is that setTimeout is an asynchronous method, meaning. Each time keeping track of a number of attempts. In this code, Print first is displayed first and then the function execution is paused for 2 seconds before the next line of code is executed. Unlike Java or Python, Javascript does not have a built-in sleep function. If you notice it calls my sleep function, and basically retries the HTTP call in 5 second intervals. ![]() In programming languages like C, Ruby, or Python pausing or delaying function execution is pretty straightforward as you would only need to call the sleep function.įor instance, consider the following Python function: import time ![]() However, there are different methods you can use to implement its functionality. The Node.Js sleep function does not exist. The programming languages such as PHP and C has a sleep(sec) function to pause the execution for a fixed amount of time. How can we sleep or delay using Node.Js Javascript?
0 Comments
Leave a Reply. |