Skip to content

Instantly share code, notes, and snippets.

@enishant
Forked from ramonvictor/wait-function.js
Created June 29, 2022 08:30
Show Gist options
  • Save enishant/36bd3e3277373876bbdc875acba5e7d3 to your computer and use it in GitHub Desktop.
Save enishant/36bd3e3277373876bbdc875acba5e7d3 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