OLD | NEW |
(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 |
OLD | NEW |