Skip to content

Instantly share code, notes, and snippets.

@eviltrout
Created April 8, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eviltrout/5338573 to your computer and use it in GitHub Desktop.
Save eviltrout/5338573 to your computer and use it in GitHub Desktop.
Discourse.debouncePromise = function(func, wait) {
var timeout = null;
return function() {
var context = this;
var args = arguments;
// Return a promise that is never executed
if (timeout) return Ember.Deferred.create();
return Ember.Deferred.promise(function(promise) {
timeout = Em.run.later(function () {
timeout = null;
promise.resolve(func.apply(context, args));
}, wait);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment