---
title: "Discussion on \"Write a function that returns a promise and resolves after a specified delay. Use it to simulate asynchronous operations.\" | Hashnode"
description: "Discussion on \"Write a function that returns a promise and resolves after a specified delay. Use it to simulate asynchronous operations.\". function delay(ms) {\n  return new Promise((resolve) => {\n    setTimeout(resolve, ms);\n  });\n}"
url: "https://hashnode.com/posts/write-a-function-that-returns-a-promise/648efeb9d12c05e4b299de59"
---

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

Discussion

# [Write a function that returns a promise and resolves after a specified delay. Use it to simulate asynchronous operations.](https://startdev.hashnode.dev/write-a-function-that-returns-a-promise?utm_source=hashnode&utm_medium=feed)

function delay(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); }

Jun 18, 2023 · 1 min read · startdev.hashnode.dev  
Read the article

-   [#node-js](https://hashnode.com/tag/node-js)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#promises](https://hashnode.com/tag/promises)
-   [#asynchronous](https://hashnode.com/tag/asynchronous)
-   [#asynchronous-javascript](https://hashnode.com/tag/asynchronous-javascript)

## Written by

[Rahul Kumar](https://hashnode.com/@RahulKaran)

@RahulKaran

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

Lets make something useful by learning

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
