import/DownloadTaskCollection.js
/**
     * @param {DownloadTask[]} tasks All the tasks that must be executed
     * @param {number} parallelTasks How many tasks to run in parallel
     */
@param {DownloadTask[]} tasks All the tasks that must be executed
@param {number} parallelTasks How many tasks to run in parallel
@param { DownloadTask [] } tasks All the tasks that must be executed @param { number } parallelTasks How many tasks to run in parallel
run(tasks, parallelTasks = config.maxParallelDownloads)
    {
        const queue = new Queue(tasks);
        const next = () => {
            const task = queue.dequeue();
            if (!task) {
                return Promise.resolve();
            }
            return task.start().then(async (stream) => {
                task.response.once("end", next);
                stream.pipe(new DatabaseWriter());
            });
        };
        let batch = [];
        while (parallelTasks-- && !queue.isEmpty()) {
            batch.push(next());
        }
        return Promise.all(batch);
    }
run ( tasks , parallelTasks = config . maxParallelDownloads ) { const queue = new Queue ( tasks ) ; const next = ( ) => { const task = queue . dequeue ( ) ; if ( ! task ) { return Promise . resolve ( ) ; } return task . start ( ) . then ( async ( stream ) => { task . response . once ( "end" , next ) ; stream . pipe ( new DatabaseWriter ( ) ) ; } ) ; } ; let batch = [ ] ; while ( parallelTasks -- && ! queue . isEmpty ( ) ) { batch . push ( next ( ) ) ; } return Promise . all ( batch ) ; }
@param {DownloadTask[]} tasks All the tasks that must be executed
 @param {number} parallelTasks How many tasks to run in parallel
@param { DownloadTask [] } tasks All the tasks that must be executed @param { number } parallelTasks How many tasks to run in parallel
// Create a queue of tasks // A function to be called on any task completion // console.log(queue.size()) // Begin with the initial batch