DEV Community

Cover image for Wait!
Thomas Rigby
Thomas Rigby

Posted on • Originally published at thomasxbanks.com on

3 3

Wait!

Why the rush…?!

Whether you're faking an API response, introducing deliberate cognitive drain, or simply want to slow things down this utility function has got you, baby! 😎

const delay = ms => new Promise(rv => setTimeout(rv, ms))
Enter fullscreen mode Exit fullscreen mode

Cool! How do I use it?

delay(500).then(() => console.log(`hello world`))
Enter fullscreen mode Exit fullscreen mode

Nice! Does it work with async/await?

Heck, yes, it does!

const functionName = async () => {

  doFirstThing()

  await delay(500)

  doNextThing()
}
Enter fullscreen mode Exit fullscreen mode

See the Pen Delay by thomas×banks (ツ) (@thomasxbanks) on CodePen.

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

If you found this article helpful, a little ❤️ or a friendly comment would be much appreciated!

Got it