Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created October 25, 2017 06:33
Show Gist options
  • Select an option

  • Save andrIvash/cedb0a97a4912eed1a5c3c655581f215 to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/cedb0a97a4912eed1a5c3c655581f215 to your computer and use it in GitHub Desktop.
/**
* Resolves a Promise after a specified amount of time.
*
* @param {number} delay Milliseconds to wait before resolving.
* @param {any} value Argument to be resolved by this Promise.
*
* @return {Promise} Promise which will be resolved after passed time.
*
* @example
* const delay = require('nanodelay')
*
* delay(300, "foo").then(result => {
* // Executed after 300 milliseconds
* result //=> "foo"
* })
*
* @name nanodelay
*/
module.exports = function (delay, value) {
return new Promise(function (resolve) {
setTimeout(resolve, delay, value)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment