throat icon indicating copy to clipboard operation
throat copied to clipboard

Any way to handle a dynamic input?

Open erikian opened this issue 3 years ago • 0 comments

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.

erikian avatar Jul 12 '21 14:07 erikian