diff --git a/lib/extend.js b/lib/extend.js index eea88da..1203780 100644 --- a/lib/extend.js +++ b/lib/extend.js @@ -6,6 +6,21 @@ module.exports = function (Potential, $Promise) { //----- promise methods ----- + $Promise.debounce = function (sourceFn) { + var pending; + function resetPending () { + pending = null; + } + resetPending(); + return function () { + if (!pending) { + pending = Promise.resolve(sourceFn.apply(this, arguments)); + pending.then(resetPending, resetPending); + } + return pending; + }; + }; + // syntactic sugar for adding error handlers $Promise.prototype.catch = function (onRejected) { return this.then(null, onRejected);