1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Making jobs and particularly preview filling job non-blocking

This commit is contained in:
Patrik J. Braun 2022-12-10 10:14:25 +01:00
parent 534f7187c4
commit d209816619
2 changed files with 6 additions and 0 deletions

View File

@ -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;
}

View File

@ -144,6 +144,9 @@ export abstract class Job<T = void> implements IJob<T> {
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);