Skip to content Skip to sidebar Skip to footer

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 goin

Solution 1:

The general approach is to have a shared promise to queue onto:

let queue = Promise.resolve();
functionsomeEventOccured(data:string) {
  queue = queue.then(() => {
    returnhandleEvent(data);
  }).catch(err => {
    // ensure `queue` is never rejected or it'll stop processing events// …
  });
}

Of course, this does implicitly store the data events in the closures on the promise chain.

Post a Comment for "Js: Executing Events Overlapping In Time Afteranother"