JS: Executing events overlapping in time afteranother

I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first).

The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order...

async someEventOccured(data:string){
   await handleEvent(data);
}

I have already tried using .then() and storing the promise, however I have no idea how to wait for the previous .then() to finish...

Your help is very appreciated <3



Read more here: https://stackoverflow.com/questions/64955564/js-executing-events-overlapping-in-time-afteranother

Content Attribution

This content was originally published by Martin Dallinger at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: