NodeJS system to queue, batch, and process.
I found myself nesting queues whenever I needed to loop through multiple arrays. So I added a mix
function to help with this. Here’s what I was doing.
// Honestly, I'm not sure how you would effeciently cap threads on this.
await qbp(teachers, (teacher) => {
await qbp(classRooms, (classRoom) => {
await qbp(students, (student) => {
await addStudent(teacher, classRoom, student);
});
});
});
async function addStudent(teacher, classRoom, student) {
// No one likes to nest stuff.
}
So instead, now we can use the qbp.mix()
function.
// Now we can definitely cap the threads if we want.
await qbp.mix([teachers, classRooms, students], (...args) => addStudent(...args), { threads: 5 });
async function addStudent(teacher, classRoom, student, { queue }) {
// The parameters mirror the same order you gave them to qbp.
}