Skip to content

Instantly share code, notes, and snippets.

@ramonvictor
Created April 23, 2016 16:05
Show Gist options
  • Save ramonvictor/67b894b7d07e1ef777f5432602cd8112 to your computer and use it in GitHub Desktop.
Save ramonvictor/67b894b7d07e1ef777f5432602cd8112 to your computer and use it in GitHub Desktop.
Fancy setTimeout wrapper using native Promise.
var wait = function(ms) {
ms = ms || 500;
return new Promise(function(resolve, reject){
window.setTimeout(function() {
resolve();
}, ms);
});
};
// USAGE
// ---------
wait(500).then(function() {
// Do stuff after 500ms
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment