OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @param {number} timeout | 7 * @param {number} timeout |
8 */ | 8 */ |
9 WebInspector.Throttler = function(timeout) | 9 WebInspector.Throttler = function(timeout) |
10 { | 10 { |
11 this._timeout = timeout; | 11 this._timeout = timeout; |
12 this._isRunningProcess = false; | 12 this._isRunningProcess = false; |
13 this._asSoonAsPossible = false; | 13 this._asSoonAsPossible = false; |
14 /** @type {?function():(!Promise.<?>)} */ | 14 /** @type {?function():(!Promise.<?>)} */ |
15 this._process = null; | 15 this._process = null; |
16 this._lastCompleteTime = 0; | |
16 } | 17 } |
17 | 18 |
18 WebInspector.Throttler.prototype = { | 19 WebInspector.Throttler.prototype = { |
19 _processCompleted: function() | 20 _processCompleted: function() |
20 { | 21 { |
22 this._lastCompleteTime = Date.now(); | |
caseq
2016/05/05 01:39:19
performance.now() * 1000?
| |
21 this._isRunningProcess = false; | 23 this._isRunningProcess = false; |
22 if (this._process) | 24 if (this._process) |
23 this._innerSchedule(false); | 25 this._innerSchedule(false); |
24 this._processCompletedForTests(); | 26 this._processCompletedForTests(); |
25 }, | 27 }, |
26 | 28 |
27 _processCompletedForTests: function() | 29 _processCompletedForTests: function() |
28 { | 30 { |
29 // For sniffing in tests. | 31 // For sniffing in tests. |
30 }, | 32 }, |
(...skipping 15 matching lines...) Expand all Loading... | |
46 * @param {function():(!Promise.<?>)} process | 48 * @param {function():(!Promise.<?>)} process |
47 * @param {boolean=} asSoonAsPossible | 49 * @param {boolean=} asSoonAsPossible |
48 */ | 50 */ |
49 schedule: function(process, asSoonAsPossible) | 51 schedule: function(process, asSoonAsPossible) |
50 { | 52 { |
51 // Deliberately skip previous process. | 53 // Deliberately skip previous process. |
52 this._process = process; | 54 this._process = process; |
53 | 55 |
54 // Run the first scheduled task instantly. | 56 // Run the first scheduled task instantly. |
55 var hasScheduledTasks = !!this._processTimeout || this._isRunningProcess ; | 57 var hasScheduledTasks = !!this._processTimeout || this._isRunningProcess ; |
56 asSoonAsPossible = !!asSoonAsPossible || !hasScheduledTasks; | 58 asSoonAsPossible = !!asSoonAsPossible || (!hasScheduledTasks && Date.now () - this._lastCompleteTime > this._timeout); |
caseq
2016/05/05 01:39:19
ditto.
| |
57 | 59 |
58 var forceTimerUpdate = asSoonAsPossible && !this._asSoonAsPossible; | 60 var forceTimerUpdate = asSoonAsPossible && !this._asSoonAsPossible; |
59 this._asSoonAsPossible = this._asSoonAsPossible || asSoonAsPossible; | 61 this._asSoonAsPossible = this._asSoonAsPossible || asSoonAsPossible; |
60 | 62 |
61 this._innerSchedule(forceTimerUpdate); | 63 this._innerSchedule(forceTimerUpdate); |
62 }, | 64 }, |
63 | 65 |
64 /** | 66 /** |
65 * @param {boolean} forceTimerUpdate | 67 * @param {boolean} forceTimerUpdate |
66 */ | 68 */ |
(...skipping 24 matching lines...) Expand all Loading... | |
91 * @return {number} | 93 * @return {number} |
92 */ | 94 */ |
93 _setTimeout: function(operation, timeout) | 95 _setTimeout: function(operation, timeout) |
94 { | 96 { |
95 return setTimeout(operation, timeout); | 97 return setTimeout(operation, timeout); |
96 } | 98 } |
97 } | 99 } |
98 | 100 |
99 /** @typedef {function(!Error=)} */ | 101 /** @typedef {function(!Error=)} */ |
100 WebInspector.Throttler.FinishCallback; | 102 WebInspector.Throttler.FinishCallback; |
OLD | NEW |