---
title: "Discussion on \"Sleep method to wait before executing the next code\" | Hashnode"
description: "Discussion on \"Sleep method to wait before executing the next code\". const sleep = (delay) => {\n  return new Promise((resolve, reject) => {\n    setTimeout(resolve, delay);\n  });\n};\n\nasync function processData() {\n  console.log(\"Print immediately\")\n  await sleep(5000);\n  console.log(\"Print after 5 seconds\")\n}\n\nprocessD..."
url: "https://hashnode.com/posts/sleep-method-to-wait-before-executing-the-next-code/638638207893759c464f0aa0"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Sleep method to wait before executing the next code](https://harikrishna.hashnode.dev/sleep-method-to-wait-before-executing-the-next-code?utm_source=hashnode&utm_medium=feed)

const sleep = (delay) => { return new Promise((resolve, reject) => { setTimeout(resolve, delay); }); }; async function processData() { console.log("Print immediately") await sleep(5000); console.log("Print after 5 seconds") } processD...

Nov 29, 2022 · 1 min read · harikrishna.hashnode.dev  
Read the article

-   [#sleep](https://hashnode.com/tag/sleep)
-   [#settimeout](https://hashnode.com/tag/settimeout)

## Written by

[Hari Krishna Anem](https://hashnode.com/@hkrishna)

@hkrishna · Hyderabad, India

  
[View profile](https://hashnode.com/@hkrishna)

Full stack developer

Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
