You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
srap/src/util/async-interval.js

25 lines
555 B
JavaScript

"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();
};