PentaCode

03 – Exploring Async.js – async.queue2 min read

Async.queue creates a queue object with the specified concurrency. Tasks added to the queue are processed in parallel (up to the concurrency limit). If all workers are in progress, the task is queued until one becomes available. Once a worker completes a task, that task’s callback is called.

We’re logging the task name via task.name, and we check the remaining tasks by calling tasksQueue.length(), we’re also setting a delay of 1 second to simulate intensive processing. The second parameter of 5 means we’re processing 5 of them at a time in parallel.