DEV Community

sakethk
sakethk

Posted on

7 2

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs