import/DownloadTaskCollection.js
/**
     * Makes the requests for each of the included tasks. Each response is
     * expected to return a "content-length" header which we use to compute the
     * `total` property of this task.
     * Note that some of these requests might fail early (e.g. 404). For that
     * reason we use `Promise.allSettled` instead of `Promise.all`.
     */
Makes the requests for each of the included tasks. Each response is
expected to return a "content-length" header which we use to compute the
`total` property of this task.
Note that some of these requests might fail early .
Makes the requests for each of the included tasks . Each response is expected to return a " content - length " header which we use to compute the ` total ` property of this task . Note that some of these requests might fail early .
init(parallelTasks = config.maxParallelDownloads)
    {
        const onError = (task, error) => {
            task.end(error);
        };
        const queue = new Queue(this.files.map(fileInfo => {
            const task = new DownloadTask(fileInfo);
            this.tasks.push(task);
            task.once("error", error => onError(task, error));
            return task;
        }));
        const next = () => {
            const task = queue.dequeue();
            if (!task) {
                return Promise.resolve();
            }
            return task.init()
                .then(() => this.total += task.total)
                .catch(error => onError(task, error))
                .finally(next);
        };
        let batch = [];
        while (parallelTasks-- && !queue.isEmpty()) {
            batch.push(next());
        }
        return Promise.all(batch);
    }
init ( parallelTasks = config . maxParallelDownloads ) { const onError = ( task , error ) => { task . end ( error ) ; } ; const queue = new Queue ( this . files . map ( fileInfo => { const task = new DownloadTask ( fileInfo ) ; this . tasks . push ( task ) ; task . once ( "error" , error => onError ( task , error ) ) ; return task ; } ) ) ; const next = ( ) => { const task = queue . dequeue ( ) ; if ( ! task ) { return Promise . resolve ( ) ; } return task . init ( ) . then ( ( ) => this . total += task . total ) . catch ( error => onError ( task , error ) ) . finally ( next ) ; } ; let batch = [ ] ; while ( parallelTasks -- && ! queue . isEmpty ( ) ) { batch . push ( next ( ) ) ; } return Promise . all ( batch ) ; }
Makes the requests for each of the included tasks.
Makes the requests for each of the included tasks .
// On error set the `error` property // A function to be called on any task completion // Begin with the initial batch