MessageReceiver.queueAllCached: Give event loop a rest
We don't want to queue multiple hundreds of messages at once, so we let the event loop catch up every 20 messages queued.
This commit is contained in:
parent
b3d56276a8
commit
15751f3521
1 changed files with 10 additions and 5 deletions
|
@ -268,12 +268,17 @@ MessageReceiver.prototype.extend({
|
||||||
ev.count = count;
|
ev.count = count;
|
||||||
this.dispatchEvent(ev);
|
this.dispatchEvent(ev);
|
||||||
},
|
},
|
||||||
queueAllCached() {
|
async queueAllCached() {
|
||||||
return this.getAllFromCache().then(items => {
|
const items = await this.getAllFromCache();
|
||||||
for (let i = 0, max = items.length; i < max; i += 1) {
|
for (let i = 0, max = items.length; i < max; i += 1) {
|
||||||
this.queueCached(items[i]);
|
if (i > 0 && i % 20 === 0) {
|
||||||
|
window.log.info('queueAllCached: Giving event loop a rest');
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
this.queueCached(items[i]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async queueCached(item) {
|
async queueCached(item) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue