Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: Source/devtools/front_end/common/Throttler.js

Issue 319143002: DevTools: introduce WebInspector.Throttler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @param {number} timeout
8 */
9 WebInspector.Throttler = function(timeout)
10 {
11 this._timeout = timeout;
12 this._isRunningProcess = false;
13 this._somethingScheduled = false;
14 }
15
16 WebInspector.Throttler.prototype = {
17 _processCompleted: function()
18 {
19 this._isRunningProcess = false;
20 if (this._somethingScheduled)
21 this.schedule(this._process);
22 },
23
24 _onProcessTimeout: function()
25 {
26 this._processTimeout = null;
27 this._somethingScheduled = false;
28 this._isRunningProcess = true;
29 this._process(this._processCompleted.bind(this));
30 },
31
32 /**
33 * @param {function(function())} process
34 */
35 schedule: function(process)
36 {
37 this._somethingScheduled = true;
38 this._process = process;
39
40 if (this._isRunningProcess)
41 return;
42
43 if (!this._processTimeout)
44 this._processTimeout = setTimeout(this._onProcessTimeout.bind(this), this._timeout);
45 }
46 }
47
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698