□□ This log will show after 5 secondsĪnd so on and so forth you can call the delay function whenever you want and can pass the suitable waiting time as a parameter. □□ This log will show after 2 seconds let browser = await puppeteer.launch() Samples: const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)) The setTimeout will call the resolve function after it waits for the milliseconds time, then the delay function will return to its outer scope and will continue in executing the next line. In the above function, we’ve passed a parameter milliseconds to the setTimeout function, along with the resolve function from the Promise. ![]() const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)) ![]() We can create the following JS delay function, that will delay the execution of the next line for N seconds. Examples 1- Using custom delay implementation.
0 Comments
Leave a Reply. |