Skip to content

Instantly share code, notes, and snippets.

@umcconnell
Created May 26, 2019 16:50
Show Gist options
  • Save umcconnell/7962242be2a882f9771b177e41b3dd1c to your computer and use it in GitHub Desktop.
Save umcconnell/7962242be2a882f9771b177e41b3dd1c to your computer and use it in GitHub Desktop.
Fancy JS setTimeout function
/**
* JS promisified setTimeout
*
* @param {number} ms timeout time in ms
* @example
* wait(2000).then(console.log)
* // => logs after 2 seconds
* @returns {Promise} A promise that resolves after the specified time `ms`
*/
let wait = ms => new Promise(res => setTimeout(res, ms));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment