Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created February 21, 2017 18:58
Show Gist options
  • Save Kcko/29aaa9c02d9b0cca1cf7699a7e4ebd2c to your computer and use it in GitHub Desktop.
Save Kcko/29aaa9c02d9b0cca1cf7699a7e4ebd2c to your computer and use it in GitHub Desktop.
function timeout(milliseconds) {
// Create a new Deferred object
var deferred = $.Deferred();
// Resolve the Deferred after the amount of time specified by milliseconds
setTimeout(deferred.resolve, milliseconds);
// Return the Deferred's Promise object
return deferred.promise();
}
timeout(1000).then(function() {
console.log('I waited for 1 second!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment