debounce update log writer

This commit is contained in:
tophf 2017-04-27 02:06:16 +03:00
parent a22874a898
commit f0dc13cd2e

View File

@ -128,17 +128,27 @@ var updater = {
updater.schedule(); updater.schedule();
}, },
log(text) { log: (() => {
chromeLocal.getValue('updateLog').then((lines = []) => { let queue = [];
const time = text && performance.now() - (updater.log.lastWriteTime || 0) > 10e3 let lastWriteTime = 0;
? new Date().toLocaleString() + '\t' return text => {
: ''; queue.push(text);
lines.splice(0, lines.length - 1000); debounce(flushQueue, 1e3);
lines.push(time + text); };
chromeLocal.setValue('updateLog', lines); function flushQueue() {
updater.log.lastWriteTime = performance.now(); chromeLocal.getValue('updateLog').then((lines = []) => {
}); // our XHR timeout is 10 seconds
}, const time = performance.now() - lastWriteTime > 11e3
? new Date().toLocaleString() + '\t'
: '';
lines.splice(0, lines.length - 1000);
lines.push(...queue.map(item => item ? time + item : ''));
chromeLocal.setValue('updateLog', lines);
lastWriteTime = performance.now();
queue = [];
});
}
})(),
}; };
updater.schedule(); updater.schedule();