J
J
jslby2020-12-18 10:52:47
Node.js
jslby, 2020-12-18 10:52:47

How to run a function asynchronously in NodeJS?

Hello!
There is a function like this one:

const myFunc = async () => {
      let data = redis.pop('list_name');
      let response = await fetch('https://api.github.com/users/' + data);
      log.add(response.status);
}

I need something like threads, but only parallel asynchronous execution. Those. it is necessary to execute this function in an infinite loop, but the maximum number of parallel executions should be, for example, 5. I tried to implement it through async.queue, but there is no possibility of infinite execution. Now I think in the direction of for of inside the function. Tell me, how would you implement such a task? Ideally, when the records in the radish end, the script stops working

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question