smarter redraws of drive/settings usage bar

This commit is contained in:
ansuz
2017-06-30 11:20:40 +02:00
parent d2085c1269
commit b8934c0b97
2 changed files with 54 additions and 11 deletions

View File

@@ -135,6 +135,25 @@ define([], function () {
return g;
};
/* takes a function (f) and a time (t) in ms. returns a function wrapper
which prevents the internal function from being called more than once
every t ms. if the function is prevented, returns time til next valid
execution, else null.
*/
Util.notAgainForAnother = function (f, t) {
if (typeof(f) !== 'function' || typeof(t) !== 'number') {
throw new Error("invalid inputs");
}
var last = null;
return function () {
var now = +new Date();
if (last && now <= last + t) { return t - (now - last); }
last = now;
f();
return null;
};
};
Util.createRandomInteger = function () {
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
};