diff --git a/src/backend/model/database/sql/AlbumManager.ts b/src/backend/model/database/sql/AlbumManager.ts index 0416ff03..c67c78bb 100644 --- a/src/backend/model/database/sql/AlbumManager.ts +++ b/src/backend/model/database/sql/AlbumManager.ts @@ -106,6 +106,9 @@ export class AlbumManager implements IAlbumManager { for (const a of albums) { await AlbumManager.updateAlbum(a as SavedSearchEntity); + // giving back the control to the main event loop (Macrotask queue) + // https://blog.insiderattack.net/promises-next-ticks-and-immediates-nodejs-event-loop-part-3-9226cbe7a6aa + await new Promise(setImmediate); } this.isDBValid = true; } diff --git a/src/backend/model/jobs/jobs/Job.ts b/src/backend/model/jobs/jobs/Job.ts index 7ebb7478..5538c4ec 100644 --- a/src/backend/model/jobs/jobs/Job.ts +++ b/src/backend/model/jobs/jobs/Job.ts @@ -144,6 +144,9 @@ export abstract class Job implements IJob { this.onFinish(); return; } + // giving back the control to the main event loop (Macrotask queue) + // https://blog.insiderattack.net/promises-next-ticks-and-immediates-nodejs-event-loop-part-3-9226cbe7a6aa + await new Promise(setImmediate); this.run(); } catch (e) { Logger.error(LOG_TAG, e);