Skip to content

Instantly share code, notes, and snippets.

@eightHundreds
Created April 30, 2019 02:58
Show Gist options
  • Save eightHundreds/e8cb3b6748a429f51cd3a3db1752b0a3 to your computer and use it in GitHub Desktop.
Save eightHundreds/e8cb3b6748a429f51cd3a3db1752b0a3 to your computer and use it in GitHub Desktop.
function timeout(funct, args, time) {
var deferred = new jQuery.Deferred(),
promise = funct.apply(null, args);
if (promise) {
$.when(promise)
.done(deferred.resolve)
.fail(deferred.reject)
.progress(deferred.notify);
}
setTimeout(function() {
deferred.reject();
}, time);
return deferred.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment