Skip to content

Commit

Permalink
MessageReceiver.queueAllCached: Give event loop a rest
Browse files Browse the repository at this point in the history
We don't want to queue multiple hundreds of messages at once, so we
let the event loop catch up every 20 messages queued.
  • Loading branch information
scottnonnenberg-signal committed Aug 16, 2018
1 parent b3d5627 commit 15751f3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions libtextsecure/message_receiver.js
Expand Up @@ -268,12 +268,17 @@ MessageReceiver.prototype.extend({
ev.count = count;
this.dispatchEvent(ev);
},
queueAllCached() {
return this.getAllFromCache().then(items => {
for (let i = 0, max = items.length; i < max; i += 1) {
this.queueCached(items[i]);
async queueAllCached() {
const items = await this.getAllFromCache();
for (let i = 0, max = items.length; i < max; i += 1) {
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) {
try {
Expand Down

0 comments on commit 15751f3

Please sign in to comment.