Promisify setTimeout

sakethkowtha

sakethk

Posted on October 9, 2021

Promisify setTimeout

Code to promisify setTimeout

const delay = (time) => new Promise((resolve, reject) => setTimeout(resolve, time))
Enter fullscreen mode Exit fullscreen mode

Usage

delay(2000).then(() => console.log('Hello i will get logged after 2 second(s)'))
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
sakethkowtha
sakethk

Posted on October 9, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related