Style things from PR comments
This commit is contained in:
parent
63776509a6
commit
239abf4eca
1 changed files with 5 additions and 4 deletions
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function(f, min_interval_ms) {
|
module.exports = function(f, minIntervalMs) {
|
||||||
this.lastCall = 0;
|
this.lastCall = 0;
|
||||||
this.scheduledCall = undefined;
|
this.scheduledCall = undefined;
|
||||||
|
|
||||||
|
@ -22,16 +22,17 @@ module.exports = function(f, min_interval_ms) {
|
||||||
return function() {
|
return function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
if (self.lastCall < now - min_interval_ms) {
|
if (self.lastCall < now - minIntervalMs) {
|
||||||
f.apply(this);
|
f.apply(this);
|
||||||
self.lastCall = now;
|
self.lastCall = now;
|
||||||
} else if (self.scheduledCall === undefined) {
|
} else if (self.scheduledCall === undefined) {
|
||||||
self.scheduledCall = setTimeout(() => {
|
self.scheduledCall = setTimeout(
|
||||||
|
() => {
|
||||||
self.scheduledCall = undefined;
|
self.scheduledCall = undefined;
|
||||||
f.apply(this);
|
f.apply(this);
|
||||||
self.lastCall = now;
|
self.lastCall = now;
|
||||||
},
|
},
|
||||||
(self.lastCall + min_interval_ms) - now
|
(self.lastCall + minIntervalMs) - now
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue