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();
function someEventOccured(data:string) {
queue = queue.then(() => {
return handleEvent(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"