Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View danieljsj's full-sized avatar

Daniel Schulz-Jackson danieljsj

View GitHub Profile
@danieljsj
danieljsj / delay-promise.js
Last active October 26, 2018 23:34 — forked from thommyhh/delay-promise.js
JavaScript delayed promise
// Sometimes it is helpful/necessary to create a promise, that delays the execution.
// This very general/generic snippet returns a promise, that is resolved after a given timeout.
// The `min` and `max` arguments are used to calcuate a random delay in the range between `min` and `max`
let delay = (min, max) => {
return new Promise(resolve => {
setTimeout(resolve, Math.random() * (max - min) + min)
})
}
// The next 3 lines of code are an example of how to use `delay()` in general: