Skip to content

Instantly share code, notes, and snippets.

@Odepax
Created September 21, 2019 10:32
Show Gist options
  • Save Odepax/4d4d50ac4c1ecf38f900e42ec7a2d622 to your computer and use it in GitHub Desktop.
Save Odepax/4d4d50ac4c1ecf38f900e42ec7a2d622 to your computer and use it in GitHub Desktop.
Javascript Promise.delay
/** Returns a promise that resolves after 'timeout' ms. */
Promise.delay = function delay(/** @type {number} @description Unit: ms. */ timeout, value = undefined) {
return new Promise(resolve => setTimeout(() => resolve(value), timeout))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment