Skip to content

Instantly share code, notes, and snippets.

danieljsj

Block or report user

Report or block danieljsj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danieljsj
danieljsj / delay-promise.js
Last active Oct 26, 2018 — forked from thommyhh/delay-promise.js
JavaScript delayed promise
View delay-promise.js
// 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:
You can’t perform that action at this time.