Track current queue sizes as a metric
parent
5b8e71c083
commit
e40113a701
@ -0,0 +1,24 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const Promise = require("bluebird");
|
||||||
|
|
||||||
|
module.exports = function asyncInterval(interval, callback) {
|
||||||
|
function doCycle() {
|
||||||
|
let startTime = Date.now();
|
||||||
|
|
||||||
|
return Promise.try(() => {
|
||||||
|
return callback();
|
||||||
|
}).then(() => {
|
||||||
|
// let elapsed = Date.now() - startTime;
|
||||||
|
let elapsed = 0; // HACK: Temporary way to force that the full interval is always waited *between* operations
|
||||||
|
|
||||||
|
if (elapsed > interval) {
|
||||||
|
return doCycle();
|
||||||
|
} else {
|
||||||
|
return Promise.delay(interval - elapsed).then(doCycle);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return doCycle();
|
||||||
|
};
|
Loading…
Reference in New Issue