Let’s start with a naïve implementation, using just normal iteration: – – This small code inside is, basically, a reducer, but with asynchronous flow!

Let’s generalize it, so we’ll pass handler there: – – Now we have fully generalized reducer, but as you can see, the amount of code in our function stayed almost the same in size – so, in case you use once or twice, it might be not that beneficial to…

Well, another new feature of modern JS is generators, and you can use them to essentially repeat the same behaviour (and almost the syntax!)

The only problem is the following: – – Apparently, not so many projects/people dive into generators, due to their complicated nature and alternatives, and because of that, I’ll separate our immediately, so you can hide implementation details: – – You can see that our interface remained the same, but the…

While the amount of code is not bigger (it might be even smaller), it is less readable and has to wrap your head around it – however, it works exactly the same.