Tech Rumors
3 subscribers
235K photos
239K links
Download Telegram
dev.to

Creating Async Task Runner with Concurrency in JavaScript
Let us consider we need to create an aync task runner in javascript with the following constraint:

The task runner should have a set of tasks that will be pushed to it,
Each of these tasks will be some async operation,
The task runner should also ensure that at a single point of time only a given number of tasks can perform, and other tasks keep on waiting unless their turn comes.

Let's code out the solution first

class Runner{
constructor(concurrency=1){
this.concurrency = concurrency;
t…
#javascript #async #concurrency #scheduler