throat
throat copied to clipboard
Any way to handle a dynamic input?
Hello, I'm building an upload queue and I'd like to know if it's possible to add more files after calling throat, e.g.: `
let uploadedFiles = 0
const throat = require('throat')(10)
// uploadQueue initially has 20 files
for (const upload of uploadQueue) {
throat(async () => {
// logic for processing upload
uploadedFiles++;
console.log({ uploadedFiles, remainingFiles: uploadQueue.length - uploadedFiles })
})
}
// add another file to the queue
uploadQueue.push(newUpload)
In the above example, I get { uploadedFiles: 20, remainingFiles: 1 }
after the initial 20 files are processed and the queue never gets to the new upload. Is there any way to listen to changes in uploadQueue
? Or do I have to call throat again every time I add more items to the queue?
Thanks in advance.