pvopk.blogg.se

Javascript thread sleep
Javascript thread sleep





Under the async function, we have used the keyword await() to suspend the second console.log() function until the promise has been resolved this takes an average of 4 seconds. We will name this function sleep() however, that does not stop you from naming it to any other name that you may find appropriate. However, using an asynchronous promise-based function, we can use the keyword await() to pause the execution of a piece of code until that promise is fulfilled first.

javascript thread sleep

Unlike other programming languages such as C that provide a sleep function, which allows us to sleep a given thread while waiting for another to execute, JavaScript doesn’t have this function.

javascript thread sleep

Use the await() Keyword to Pause Execution of Codes in Node.js

javascript thread sleep

Function repeatedly executed after every 2 seconds!







Javascript thread sleep