const daily_queue = [];
const one_day = 86400000; // 1000 * 60 * 60 * 24
const today = new Date() // get today's date
const tomorrow = new Date(today)
tomorrow.setDate(today.getDate() + 1)
tomorrow.setHours(0, 0, 0, 0)
const timeout_remaining = tomorrow.getTime() - today.getTime();
setTimeout(process_daily_queue, timeout_remaining);
function process_daily_queue() {
daily_queue.forEach(function(callback) {
callback();
});
setTimeout(process_daily_queue, one_day);
}
module.exports = {
add_to_daily_queue: function(callback) {
daily_queue.push(callback);
}
};