Index: chrome/browser/resources/md_bookmarks/timer_proxy.js |
diff --git a/chrome/browser/resources/md_bookmarks/timer_proxy.js b/chrome/browser/resources/md_bookmarks/timer_proxy.js |
index de96c7fdb4ec7aa2b5bfe9c2329ccaff095de13f..88ae8762f58fdd07aa2f094162042e30f8f0c274 100644 |
--- a/chrome/browser/resources/md_bookmarks/timer_proxy.js |
+++ b/chrome/browser/resources/md_bookmarks/timer_proxy.js |
@@ -27,7 +27,51 @@ cr.define('bookmarks', function() { |
}, |
}; |
+ /** |
+ * A timer which will fire on the next task after the last time it is reset. |
calamity
2017/07/26 05:36:06
nit: This isn't strictly true. It gets added to th
tsergeant
2017/07/26 06:34:07
Done.
|
+ * @param {function()} callback |
+ * @constructor |
+ */ |
+ function Debouncer(callback) { |
tsergeant
2017/07/25 00:13:00
I'm happy enough with this for now, but one unansw
calamity
2017/07/26 05:36:06
Acknowledged.
|
+ this.callback_ = callback; |
+ this.timerProxy_ = new TimerProxy(); |
+ this.timer_ = null; |
+ this.boundTimerCallback_ = this.timerCallback_.bind(this); |
+ this.isDone_ = false; |
+ this.promiseResolver_ = new PromiseResolver(); |
calamity
2017/07/26 05:36:06
nit: Couple of types?
tsergeant
2017/07/26 06:34:07
Done.
|
+ } |
+ |
+ Debouncer.prototype = { |
+ resetTimer: function() { |
calamity
2017/07/26 05:36:06
nit: resetTimeout perhaps? This will be given a de
tsergeant
2017/07/26 06:34:07
Done.
|
+ if (this.timer_) |
+ this.timerProxy_.clearTimeout(this.timer_); |
+ this.timer_ = this.timerProxy_.setTimeout(this.boundTimerCallback_); |
+ }, |
+ |
+ /** |
+ * @return {boolean} True if the Debouncer has finished processing. |
+ */ |
+ done: function() { |
+ return this.isDone_; |
+ }, |
+ |
+ /** |
+ * @return {Promise} Promise which resolves immediately after the callback. |
+ */ |
+ get promise() { |
+ return this.promiseResolver_.promise; |
+ }, |
+ |
+ /** @private */ |
+ timerCallback_: function() { |
+ this.isDone_ = true; |
+ this.callback_.call(); |
+ this.promiseResolver_.resolve(); |
+ }, |
+ }; |
+ |
return { |
+ Debouncer: Debouncer, |
TimerProxy: TimerProxy, |
}; |
}); |