I am writing an Electron application. In the renderer process, there is a processing of an event.
The event can be triggered multiple times in such a way they may overlap. So the need is to stack and sequentially process the event instances, if they overlap.
ipcRenderer.on('doWork', function (event, args) {
doWork();
});
As the goal is to prevent overlapping of doWork
executions, have tried to make it a Promise in such a way that it executes, and if more events come in they pile up. But I am failing to build the algorithm.
Other questions that I've found on stackoverflow are always about a pre-defined/already known number of Promises (sorry if I've missed something).
Edit: questions like:
How can I execute array of promises in sequential order?
Execute many promises sequentially (Concept)
Inside doWork
I am calling electron's desktopCapturer.getSources
which is async. Then I am saving to the file system, and ensuring a maximum number of screenshots is saved, but these are using the sync Nodejs operations.