Skip to content

Commit

Permalink
Tipify resolve-promise-after-amount-of-time
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed Mar 7, 2024
1 parent d90204a commit 8b1bd45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions content/languages/javascript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ references:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
Promise: >-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
Promise(): >-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
Promise.prototype.then(): >-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
Promise.prototype.catch(): >-
Expand Down
13 changes: 7 additions & 6 deletions content/snippets/js/s/resolve-promise-after-amount-of-time.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
---
title: Resolve promise after given amount of time
type: snippet
title: Create a JavaScript promise that resolves after a given amount of time
shortTitle: Resolve promise after given amount of time
type: tip
language: javascript
tags: [function,promise]
cover: filter-coffee-pot
dateModified: 2022-01-08
excerpt: Learn how to create a promise that resolves after a given amount of time in JavaScript.
dateModified: 2024-02-28
---

Creates a promise that resolves after a given amount of time to the provided value.
Ever wanted to create an artificial pause in your JavaScript code? Did you incidentally need it to be a `Promise` instead of a simple `setTimeout()`? Well, you're in luck, because it's quite easy to create a promise that resolves after a given amount of time.

- Use the `Promise` constructor to create a new promise.
- Use `setTimeout()` to call the promise's `resolve` function with the passed `value` after the specified `delay`.
All you have to do is create a new promise using the `Promise()` constructor, and then use `setTimeout()` to call the promise's `resolve` function with the passed `value` after the specified `delay`.

```js
const resolveAfter = (value, delay) =>
Expand Down

0 comments on commit 8b1bd45

Please sign in to comment.