The following Typescript performs each call to doSomething(action) one at a time. (Meaning the second item in the list does not get a call made until the first
You can do this with a pub-sub pattern. I too am not familiar with typescipt, and I don't know if this is happening in the browser or at the backend. I'll just write the pseudoCode for this (assuming it's backend):
//I'm assuming required packages are included e.g. events = require("events");
let limit = 10;
let emitter = new events.EventEmitter();
for(let i=0; i {
console.log(`Action Done: ${actionResult}`);
emitter.emit('grabTheNextOne', listOfActions.pop());
});
}
emitter.on('grabTheNextOne', fetchNext);
EventEmitter is part of NodeJS, if you are working in Node. If in the browser, you can use the normal events model. The key idea here is the Publish-Subscribe pattern.